#include "filedata.h"
#include <QDebug>

FileData fData;

FileData::FileData()
{
    initFileData();
}

FileData::~FileData()
{
}

void FileData::initFileData()//用于角色切换 初次登录 断线重连(currentRobotFileAddres被清除了
{
    currentFileName = "";           //当前文件名(当前打开编辑的文件名)

    cmdStrWriteSuccess = false;     //程序是否有编辑 并且保存成功

    rendQuickSuccess = true;        //读成功 = 读取结束

    currentRobotFileAddress = "";

    globalDefaultUserNum = 0;

    globalDefaultToolNum = 0;

    writeAllowFLag = true;

    readAllowFlag = true;

    //fileOpenFirst = true;
}


int FileData::readProgramQuick(QString strFilePath)
{
    //qDebug()<<"currentFile :"<<QString(currentRobotFileAddress);
    if(rendQuickSuccess)
    {
        rendQuickSuccess = false;//开始读取
    }
    else
    {
        return 0 ;
    }

    QString currentFile = currentRobotFileAddress+"program/" + strFilePath;//函数内处理,不提交给全局函数
    //qDebug()<<"currentFile :"<<currentFile;

    QFile file(currentFile);

    QString lineStr;
    QString capStr;

    int fileCount = 0;

    int attrStart = 0;
    int tcdStart = 0;
    int tcdEnd = 0;

    QVector <QString> fileInfoList;

    if(file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        file.reset();
        QTextStream in(&file);

        //读取前25行
        int i = 0;
        while(!in.atEnd())
        {
            lineStr = in.readLine();
            fileInfoList.append(lineStr);

            i++;
            if(i == 25)
            {
                break;
            }
        }

        //分析
        for(int i = 0; i < fileInfoList.size();i++)
        {
            QString str = fileInfoList[i];
            if(fileInfoList[i].contains("/PROG"))
            {
                fileCount++;
                QString pattern("\\s*(/PROG)\\s*(\\w*)\\s*(.*)");
                QRegExp rx(pattern);
                str.indexOf(rx);
                if("/PROG" == rx.cap(1))
                {
                    capStr = rx.cap(2);
                    fileProInfoQuick.programName = strFilePath.toStdString();
                    currentProgramName = strFilePath;
//                    qDebug()<<__LINE__<<"*******"<<strFilePath<<endl;
                }
            }
            else if(fileInfoList[i].contains("/ATTR"))
            {
                attrStart = i;
            }
            else if(fileInfoList[i].contains("TCD:"))
            {
                tcdStart = i;
            }
            else if(fileInfoList[i].contains("DEFAULT_GROUP"))
            {
                tcdEnd = i;
                QString pattern("\\s*(DEFAULT_GROUP)\\s*(=)\\s*(.*)\\s*(;)");
                QRegExp rx(pattern);
                str.indexOf(rx);
                if("DEFAULT_GROUP" == rx.cap(1))
                {
                    capStr = rx.cap(3);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(5);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(7);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(9);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(11);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                }
            }
            else if(fileInfoList[i].contains("CONTROL_CODE"))
            {
                QString pattern("\\s*(CONTROL_CODE)\\s*(=)\\s*(.*)\\s*(;)");
                QRegExp rx(pattern);
                str.indexOf(rx);
                if("CONTROL_CODE" == rx.cap(1))
                {
                    capStr = rx.cap(3);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(5);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(7);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(9);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(11);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                }
                fileCount++;
            }
        }

        //提取内容
        if(2 == fileCount)
        {
//            qDebug()<<__FUNCTION__<<"******"<<__LINE__<<"**commandStart**"<<commandStart<<
//                   "**positionStart**"<<positionStart<<"**endLine***"<<endLine<<endl;
           for(int i = attrStart + 1;i < tcdStart;i++)
           {
               QString str = fileInfoList[i];
               if(fileInfoList[i].startsWith("OWNER"))
               {
                    QString pattern("\\s*(OWNER)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("OWNER" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.owner = capStr.toStdString();
                        //qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
               }
               else if(fileInfoList[i].startsWith("COMMENT"))
               {
                    QString pattern("\\s*(COMMENT)\\s*(=)\\s*([\\w\\s]*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("COMMENT" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.comment = capStr.toStdString();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }

               }
               else if(fileInfoList[i].startsWith("PROG_SIZE"))
               {
                     QString pattern("\\s*(PROG_SIZE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                     QRegExp rx(pattern);
                     str.indexOf(rx);
                     if("PROG_SIZE" == rx.cap(1))
                     {
                         capStr = rx.cap(3);
                         fileProInfoQuick.programSize = capStr.toInt();
//                         qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                     }
               }
               else if(fileInfoList[i].startsWith("CREATE"))
               {
                    QString pattern("\\s*(CREATE)\\s*(=)\\s*(DATE)?\\s*(\\d+)(-)(\\d+)(-)(\\d+)\\s*(TIME)?\\s*(\\d+)(:)(\\d+)(:)(\\d+)(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("CREATE" == rx.cap(1))
                    {
                        QString timeStr = "";
                        capStr = rx.cap(4);
                        timeStr += capStr + "-";
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(6);
                        timeStr += capStr + "-";
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(8);
                        timeStr += capStr + " ";
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(10) + ":";
                        timeStr += capStr;
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(12) + ":";
                        timeStr += capStr;
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(14);
                        timeStr += capStr;
//                        qDebug()<<__LINE__<<"*******"<<timeStr<<endl;

                        fileProInfoQuick.createTime = timeStr.toStdString();
                    }
               }
               else if(fileInfoList[i].startsWith("MODIFIED"))
               {
                   QString pattern("\\s*(MODIFIED)\\s*(=)\\s*(DATE)?\\s*(\\d+)(-)(\\d+)(-)(\\d+)\\s*(TIME)?\\s*(\\d+)(:)(\\d+)(:)(\\d+)(.*)");
                   QRegExp rx(pattern);
                   str.indexOf(rx);
                   if("MODIFIED" == rx.cap(1))
                   {
                       QString timeStr = "";
                       capStr = rx.cap(4);
                       timeStr += capStr + "-";
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(6);
                       timeStr += capStr + "-";
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(8);
                       timeStr += capStr;
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(10) + ": ";
                       timeStr += capStr;
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(12) + ": ";
                       timeStr += capStr;
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(14);
                       timeStr += capStr;
//                       qDebug()<<__LINE__<<"*******"<<timeStr<<endl;

                       fileProInfoQuick.modifiTime = timeStr.toStdString();
                   }
               }
               else if(fileInfoList[i].startsWith("FILE_NAME"))
               {
                   QString pattern("\\s*(FILE_NAME)\\s*(=)\\s*(\\w*)\\s*(.*)");
                   QRegExp rx(pattern);
                   str.indexOf(rx);
                   if("FILE_NAME" == rx.cap(1))
                   {
                       capStr = rx.cap(3);
                       fileProInfoQuick.fileName = capStr.toStdString();
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                   }
               }
               else if(fileInfoList[i].startsWith("VERSION"))
               {
                   QString pattern("\\s*(VERSION)\\s*(=)\\s*(\\w*)\\s*(.*)");
                   QRegExp rx(pattern);
                   str.indexOf(rx);
                   if("VERSION" == rx.cap(1))
                   {
                       capStr = rx.cap(3);
                       fileProInfoQuick.version = capStr.toStdString();
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                   }

               }
               else if(fileInfoList[i].startsWith("LINE_COUNT"))
               {
                   QString pattern("\\s*(LINE_COUNT)\\s*(=)\\s*(\\w*)\\s*(.*)");
                   QRegExp rx(pattern);
                   str.indexOf(rx);
                   if("LINE_COUNT" == rx.cap(1))
                   {
                       capStr = rx.cap(3);
                       fileProInfoQuick.lineCount = capStr.toInt();
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                   }
               }
               else if(fileInfoList[i].startsWith("MEMORY_SIZE"))
               {
                    QString pattern("\\s*(MEMORY_SIZE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("MEMORY_SIZE" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.memorySize = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
               }
               else if(fileInfoList[i].startsWith("PROTECT"))
               {
                    QString pattern("\\s*(PROTECT)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("PROTECT" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.protectPro = capStr.toStdString();
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
               }
               else if(fileInfoList[i].startsWith("TEMPLATETYPE"))
               {
                    QString pattern("\\s*(TEMPLATETYPE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);

                    if("TEMPLATETYPE" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.templateType = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
               }
            }
           for(int i = tcdStart; i < tcdEnd;i++)
           {
//               if(ENUM_COMMAND_RESET == *engineStatus)
//               {
//                   return 1;
//               }
                QString str = fileInfoList[i];
                if(fileInfoList[i].contains("STACK_SIZE"))
                {
                    QString pattern("\\s*(TCD:)\\s*(STACK_SIZE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("STACK_SIZE" == rx.cap(2))
                    {
                        capStr = rx.cap(4);
                        fileProInfoQuick.tcdStackSize = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
                }
                else if(fileInfoList[i].contains("TASK_PRIORITY"))
                {
                    QString pattern("\\s*(TASK_PRIORITY)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("TASK_PRIORITY" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.tcdTaskPriority = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
                }
                else if(fileInfoList[i].contains("TIME_SLICE"))
                {
                    QString pattern("\\s*(TIME_SLICE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("TIME_SLICE" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.tcdTimeSlice = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
                }
                else if(fileInfoList[i].contains("BUSY_LAMP_OFF"))
                {
                    QString pattern("\\s*(BUSY_LAMP_OFF)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("BUSY_LAMP_OFF" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.tcdBusyLampOff = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
                }
                else if(fileInfoList[i].contains("ABORT_REQUEST"))
                {
                    QString pattern("\\s*(ABORT_REQUEST)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("ABORT_REQUEST" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.tcdAbortRequest = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
                }
                else if(fileInfoList[i].contains("PAUSE_REQUEST"))
                {
                    QString pattern("\\s*(PAUSE_REQUEST)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("PAUSE_REQUEST" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfoQuick.tcdPauseRequest = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
                }
           }

           qDebug()<<QString::fromStdString(fileProInfoQuick.createTime);
        }

        file.close();
    }


    rendQuickSuccess = true;
    return 0;//完成
}


int FileData::readProgramToCode(QString strFilePath,QStringList &codeList)
{
    currentFile = currentRobotFileAddress+"program/" + strFilePath;

    QFile file(currentFile);
    QString lineStr;
    QString capStr;

    //codeList.clear();

    QMap<int,int> posMap;
    QVector <int> applList;
    QVector <int> bottomList;
    QVector <int> btmList;
    QVector <int> routeList;

    QVector <float> worldValue;
    worldValue.clear();
    posMap.clear();
    applList.clear();
    bottomList.clear();
    btmList.clear();
    routeList.clear();

    //bool fileFlag = false;
    int fileCount = 0;

//    int attrStart;
//    int tcdStart;
//    int tcdEnd;
//    int commandStart;
//    int positionStart;
//    int endLine;
    //2017-03-24 全部给予初始化数据
    //防止数据越界
    int attrStart = 0;
    int tcdStart = 0;
    int tcdEnd = 0;
    int commandStart = 0;
    int positionStart = 0;
    int endLine = 0;

    QVector <QString> fileInfoList;

    if(file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        file.reset();
        QTextStream in(&file);

        while(!in.atEnd())
        {
//            if(ENUM_COMMAND_RESET == *engineStatus)
//            {
//                return 1;
//            }
            lineStr = in.readLine();
            fileInfoList.append(lineStr);
        }

        for(int i = 0; i < fileInfoList.size();i++)
        {
            QString str = fileInfoList[i];
            if(fileInfoList[i].contains("/PROG"))
            {
                fileCount++;
            }
            else if(fileInfoList[i].contains("/ATTR"))
            {
                attrStart = i;
            }
            else if(fileInfoList[i].contains("TCD:"))
            {
                tcdStart = i;
            }
            else if(fileInfoList[i].contains("DEFAULT_GROUP"))
            {
                tcdEnd = i;
            }
            else if(fileInfoList[i].contains("CONTROL_CODE"))
            {
            }
            else if(fileInfoList[i].contains("/APPL"))
            {
                applList.append(i);
//                qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**APPL**"<<"i = "<<i<<endl;
            }
            else if(fileInfoList[i].contains("BOTTOM:"))
            {
                bottomList.append(i);
//                qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**bottom**"<<"i = "<<i<<endl;
            }
            else if(fileInfoList[i].contains("[BTM]{"))
            {
                btmList.append(i);
//                qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**btm**"<<"i = "<<i<<endl;
            }
            else if(fileInfoList[i].contains("ROUTE:"))
            {
                routeList.append(i);
//                qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**route**"<<"i = "<<i<<endl;
            }
            else if(fileInfoList[i].contains("/MN"))
            {
                commandStart = i;
//                qDebug() << __FUNCTION__<<"======="<<__LINE__<<"===/MN==="<<commandStart<<endl;
            }
            else if(fileInfoList[i].contains("/POS"))
            {
                positionStart = i;
//                qDebug() << __FUNCTION__<<"======="<<__LINE__<<"===/pos==="<<positionStart<<endl;
            }
            else if(fileInfoList[i].contains("/END"))
            {
                endLine = i;
                fileCount++;
            }
        }
        if(2 == fileCount)
        {
          for(int i = commandStart + 1; i < positionStart;i++)
          {
//              if(ENUM_COMMAND_RESET == *engineStatus)
//              {
//                  return 1;
//              }
              QString str = fileInfoList[i];
              QString pattern1("\\s*(\\d+)\\s*(:)\\s*(.*)");
              QString pattern2("\\s*(\\/\\/)\\s*(.*)");
              QRegExp rx1(pattern1);
              QRegExp rx2(pattern2);

              str.indexOf(rx1);
              str.indexOf(rx2);
              if(":" == rx1.cap(2))
              {
                  capStr = rx1.cap(1);
//                  qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  capStr = rx1.cap(3);
                  codeList.append(capStr);
//                  qDebug()<<__LINE__<<"*******"<<capStr<<endl;
              }
              else if("//" == rx2.cap(1))
              {
                  capStr = str;
//                  qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  codeList.append(capStr);
              }
              else//2017-03-23 缺少行编号,正常读取,但是会有会控制器的报错提示
              {
                  capStr = str;
//                  qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  cmdStrList.append(capStr);
              }
          }
          //qDebug()<<codeList;
       }
        else
        {}
        file.close();
    }

    return 0;
}


int FileData::readProgram(QString strFilePath)
{
    readAllowFlag = false;

    currentFile = currentRobotFileAddress+"program/" + strFilePath;
    currentFileName = strFilePath;

    getPointProList.clear();//补充原因:若自身打开了一个文件,另一个hmi文件打开时候
    palletStackInfo.clear();//本hmi会同步打开,直接调用read,而没有经过programDele进行清空处理
    normalPointLock.clear();

    QFile file(currentFile);
    QString lineStr;
    QString capStr;

    cmdStrList.clear();

    PointPro pointPro;
    pointPro.jointFlag = EM_CF_DEG_TYPE;

    QMap<int,int> posMap;
    QVector <int> applList;
    QVector <int> bottomList;
    QVector <int> btmList;
    QVector <int> btmEndList;//2017.03.15 需改
    QVector <int> routeList;

    QVector <float> worldValue;
    QVector <float> extWorldValue;
    worldValue.clear();
    extWorldValue.clear();
    posMap.clear();
    applList.clear();
    bottomList.clear();
    btmList.clear();
    btmEndList.clear();
    routeList.clear();

    //bool fileFlag = false;
    int fileCount = 0;

    //2017-03-24 全部给予初始化数据
    //防止数据越界
    int attrStart = 0;
    int tcdStart = 0;
    int tcdEnd = 0;
    int commandStart = 0;
    int positionStart = 0;
    int endLine = 0;

    QVector <QString> fileInfoList;

    pointPro.positionValue.clear();
    pointPro.extPositionValue.clear();

    QIODevice::OpenModeFlag tmp;

    tmp = QIODevice::ReadOnly;

    if(file.open(tmp | QIODevice::Text))
    {
        file.reset();
        QTextStream in(&file);

        while(!in.atEnd())
        {
//            if(ENUM_COMMAND_RESET == *engineStatus)
//            {
//                return 1;
//            }
            lineStr = in.readLine();
            fileInfoList.append(lineStr);
        }

        for(int i = 0; i < fileInfoList.size();i++)
        {
//            qDebug()<<"check "<<fileInfoList[i];
//            if(ENUM_COMMAND_RESET == *engineStatus)
//            {
//                return 1;
//            }
            QString str = fileInfoList[i];
            if(fileInfoList[i].contains("/PROG"))
            {
                fileCount++;
                QString pattern("\\s*(/PROG)\\s*(\\w*)\\s*(.*)");
                QRegExp rx(pattern);
                str.indexOf(rx);
                if("/PROG" == rx.cap(1))
                {
                    capStr = rx.cap(2);
                    fileProInfo.programName = strFilePath.toStdString();
                    currentProgramName = strFilePath;
//                    qDebug()<<__LINE__<<"*******"<<strFilePath<<endl;
                }
            }
            else if(fileInfoList[i].contains("/ATTR"))
            {
                attrStart = i;
            }
            else if(fileInfoList[i].contains("TCD:"))
            {
                tcdStart = i;
            }
            else if(fileInfoList[i].contains("DEFAULT_GROUP"))
            {
                tcdEnd = i;
                QString pattern("\\s*(DEFAULT_GROUP)\\s*(=)\\s*(.*)\\s*(;)");
                QRegExp rx(pattern);
                str.indexOf(rx);
                if("DEFAULT_GROUP" == rx.cap(1))
                {
                    capStr = rx.cap(3);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(5);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(7);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(9);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(11);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                }
            }
            else if(fileInfoList[i].contains("CONTROL_CODE"))
            {
                QString pattern("\\s*(CONTROL_CODE)\\s*(=)\\s*(.*)\\s*(;)");
                QRegExp rx(pattern);
                str.indexOf(rx);
                if("CONTROL_CODE" == rx.cap(1))
                {
                    capStr = rx.cap(3);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(5);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(7);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(9);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    capStr = rx.cap(11);
//                    qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                }
            }
            else if(fileInfoList[i].contains("/APPL"))
            {
                applList.append(i);
//                qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**APPL**"<<"i = "<<i<<endl;
            }
            else if(fileInfoList[i].contains("BOTTOM:"))
            {
                bottomList.append(i);
//                qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**bottom**"<<"i = "<<i<<endl;
            }
            else if(fileInfoList[i].contains("[BTM]{"))
            {
                btmList.append(i);//btm开始的地方
//                qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**btm**"<<"i = "<<i<<endl;

                int end = i + 10;
                for(int line = i;line<end;line++)
                {
                    if(fileInfoList[line].contains("};"))
                    {
                        btmEndList.append(line);//btm结束地方 2017.03.15 补充
//                        qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**btm**"<<"i = "<<line<<endl;
                        break;
                    }
                }
            }
            else if(fileInfoList[i].contains("ROUTE:"))
            {
                routeList.append(i);
//                qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**route**"<<"i = "<<i<<endl;
            }
            else if(fileInfoList[i].contains("/MN"))
            {
                commandStart = i;
                qDebug() << __FUNCTION__<<"======="<<__LINE__<<"===/MN==="<<commandStart<<endl;
            }
            else if(fileInfoList[i].contains("/POS"))
            {
                positionStart = i;
                qDebug() << __FUNCTION__<<"======="<<__LINE__<<"===/pos==="<<positionStart<<endl;
            }
            else if(fileInfoList[i].contains("/END"))
            {
                endLine = i;
                fileCount++;
            }
        }
        if(2 == fileCount)
        {
//            qDebug()<<__FUNCTION__<<"******"<<__LINE__<<"**commandStart**"<<commandStart<<
//                   "**positionStart**"<<positionStart<<"**endLine***"<<endLine<<endl;
           for(int i = attrStart + 1;i < tcdStart;i++)
           {
//               if(ENUM_COMMAND_RESET == *engineStatus)
//               {
//                   return 1;
//               }
               QString str = fileInfoList[i];
               if(fileInfoList[i].startsWith("OWNER"))
               {
                    QString pattern("\\s*(OWNER)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("OWNER" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfo.owner = capStr.toStdString();
                        //qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
               }
               else if(fileInfoList[i].startsWith("COMMENT"))
               {
                    QString pattern("\\s*(COMMENT)\\s*(=)\\s*([\\w\\s]*)\\s*(.*)");//2017.02.17修改支持空格
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("COMMENT" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfo.comment = capStr.toStdString();
                        //qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
               }
               else if(fileInfoList[i].startsWith("PROG_SIZE"))
               {
                     QString pattern("\\s*(PROG_SIZE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                     QRegExp rx(pattern);
                     str.indexOf(rx);
                     if("PROG_SIZE" == rx.cap(1))
                     {
                         capStr = rx.cap(3);
                         fileProInfo.programSize = capStr.toInt();
//                         qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                     }
               }
               else if(fileInfoList[i].startsWith("CREATE"))
               {
                    QString pattern("\\s*(CREATE)\\s*(=)\\s*(DATE)?\\s*(\\d+)(-)(\\d+)(-)(\\d+)\\s*(TIME)?\\s*(\\d+)(:)(\\d+)(:)(\\d+)(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("CREATE" == rx.cap(1))
                    {
                        QString timeStr = "";
                        capStr = rx.cap(4);
                        timeStr += capStr + "-";
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(6);
                        timeStr += capStr + "-";
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(8) + " ";
                        timeStr += capStr;
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(10) + ":";
                        timeStr += capStr;
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(12) + ":";
                        timeStr += capStr;
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                        capStr = rx.cap(14);
                        timeStr += capStr;
//                        qDebug()<<__LINE__<<"*******"<<timeStr<<endl;

                        fileProInfo.createTime = timeStr.toStdString();
                    }
               }
               else if(fileInfoList[i].startsWith("MODIFIED"))
               {
                   QString pattern("\\s*(MODIFIED)\\s*(=)\\s*(DATE)?\\s*(\\d+)(-)(\\d+)(-)(\\d+)\\s*(TIME)?\\s*(\\d+)(:)(\\d+)(:)(\\d+)(.*)");
                   QRegExp rx(pattern);
                   str.indexOf(rx);
                   if("MODIFIED" == rx.cap(1))
                   {
                       QString timeStr = "";
                       capStr = rx.cap(4);
                       timeStr += capStr + "-";
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(6);
                       timeStr += capStr + "-";
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(8);
                       timeStr += capStr + " ";
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(10) + ": ";
                       timeStr += capStr;
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(12) + ": ";
                       timeStr += capStr;
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                       capStr = rx.cap(14);
                       timeStr += capStr;
//                       qDebug()<<__LINE__<<"*******"<<timeStr<<endl;

                       fileProInfo.modifiTime = timeStr.toStdString();
                   }
               }
               else if(fileInfoList[i].startsWith("FILE_NAME"))
               {
                   QString pattern("\\s*(FILE_NAME)\\s*(=)\\s*(\\w*)\\s*(.*)");
                   QRegExp rx(pattern);
                   str.indexOf(rx);
                   if("FILE_NAME" == rx.cap(1))
                   {
                       capStr = rx.cap(3);
                       fileProInfo.fileName = capStr.toStdString();
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                   }
               }
               else if(fileInfoList[i].startsWith("VERSION"))
               {
                   QString pattern("\\s*(VERSION)\\s*(=)\\s*(\\w*)\\s*(.*)");
                   QRegExp rx(pattern);
                   str.indexOf(rx);
                   if("VERSION" == rx.cap(1))
                   {
                       capStr = rx.cap(3);
                       fileProInfo.version = capStr.toStdString();
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                   }

               }
               else if(fileInfoList[i].startsWith("LINE_COUNT"))
               {
                   QString pattern("\\s*(LINE_COUNT)\\s*(=)\\s*(\\w*)\\s*(.*)");
                   QRegExp rx(pattern);
                   str.indexOf(rx);
                   if("LINE_COUNT" == rx.cap(1))
                   {
                       capStr = rx.cap(3);
                       fileProInfo.lineCount = capStr.toInt();
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                   }
               }
               else if(fileInfoList[i].startsWith("MEMORY_SIZE"))
               {
                    QString pattern("\\s*(MEMORY_SIZE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("MEMORY_SIZE" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfo.memorySize = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
               }
               else if(fileInfoList[i].startsWith("PROTECT"))
               {
                    QString pattern("\\s*(PROTECT)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("PROTECT" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfo.protectPro = capStr.toStdString();
//                       qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
               }
               else if(fileInfoList[i].startsWith("TEMPLATETYPE"))
               {
                    QString pattern("\\s*(TEMPLATETYPE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);

                    if("TEMPLATETYPE" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfo.templateType = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
               }
            }
           for(int i = tcdStart; i < tcdEnd;i++)
           {
//               if(ENUM_COMMAND_RESET == *engineStatus)
//               {
//                   return 1;
//               }
                QString str = fileInfoList[i];
                if(fileInfoList[i].contains("STACK_SIZE"))
                {
                    QString pattern("\\s*(TCD:)\\s*(STACK_SIZE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("STACK_SIZE" == rx.cap(2))
                    {
                        capStr = rx.cap(4);
                        fileProInfo.tcdStackSize = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
                }
                else if(fileInfoList[i].contains("TASK_PRIORITY"))
                {
                    QString pattern("\\s*(TASK_PRIORITY)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("TASK_PRIORITY" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfo.tcdTaskPriority = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
                }
                else if(fileInfoList[i].contains("TIME_SLICE"))
                {
                    QString pattern("\\s*(TIME_SLICE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("TIME_SLICE" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfo.tcdTimeSlice = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
                }
                else if(fileInfoList[i].contains("BUSY_LAMP_OFF"))
                {
                    QString pattern("\\s*(BUSY_LAMP_OFF)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("BUSY_LAMP_OFF" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfo.tcdBusyLampOff = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
                }
                else if(fileInfoList[i].contains("ABORT_REQUEST"))
                {
                    QString pattern("\\s*(ABORT_REQUEST)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("ABORT_REQUEST" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfo.tcdAbortRequest = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
                }
                else if(fileInfoList[i].contains("PAUSE_REQUEST"))
                {
                    QString pattern("\\s*(PAUSE_REQUEST)\\s*(=)\\s*(\\w*)\\s*(.*)");
                    QRegExp rx(pattern);
                    str.indexOf(rx);
                    if("PAUSE_REQUEST" == rx.cap(1))
                    {
                        capStr = rx.cap(3);
                        fileProInfo.tcdPauseRequest = capStr.toInt();
//                        qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                    }
                }
           }

           //qDebug()<<QString::fromStdString(fileProInfo.createTime);//输出时间

          if(2 == applList.size())
          {
              int applStart = applList[0] + 1;      //起始行
              int applEnd = applList[1];            //结束行

              int palletSize = 0;
              int stackStyleSize = 0;
              int apprSize = 0;
              int fleeSize = 0;

//              qDebug()<<"start "<<applStart<<" ::: end "<<applEnd;

              int palletNum,stackStyleNum,apprNum,fleeNum;
//              for(int i = applStart;i < applEnd;i++)
//              {
//                    qDebug()<<i+1<<"--- ---"<<fileInfoList[i];
//              }
//              sleep(100);

              for(int i = applStart;i < applEnd;i++)
              {
//                  if(ENUM_COMMAND_RESET == *engineStatus)
//                  {
//                      return 1;
//                  }
                  QString str = fileInfoList[i];
                  if(fileInfoList[i].contains("Palletizing"))
                  {
                      apprSize = 0;
                      fleeSize = 0;
                      stackStyleSize = 0;

                      ++palletSize;

                      palletStackInfo.resize(palletSize);
                        /************************************************
                        *仅仅测试使用
                        * *******************************************/
                      regPlList.resize(palletSize);

                      palletNum = palletSize - 1;

                      QString pattern("\\s*(Palletizing)\\s*(\\[)\\s*(\\d+)\\s*(\\])\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("Palletizing" == rx.cap(1))
                      {
                          capStr = rx.cap(3);
                          palletStackInfo[palletNum].stackNumber = capStr.toInt();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      }

                      //间距允许标志
                      palletStackInfo[palletNum].intervalEnable.resize(3);
                      //间距距离
                      palletStackInfo[palletNum].intervalValue.resize(3);
                      //赋初始值
                      for(int i = 0;i< 3;i++)
                      {
                          palletStackInfo[palletNum].intervalEnable[i] = 0;
                          palletStackInfo[palletNum].intervalValue[i] = 0;
                      }
                  }
                  else if(fileInfoList[i].contains("PALLETIZING-"))
                  {
  //                    qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**PALLETIZING**"<<"i = "<<i<<endl;

                      QString pattern("\\s*(PALLETIZING-)\\s*(\\w*)\\s*(_)\\s*(\\d+)\\s*(\\w*)\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);

                      if("PALLETIZING-" == rx.cap(1))
                      {
                          int stackType = PAL_B;
                          capStr = rx.cap(2);

                          if("B" == capStr)
                          {
                              stackType = PAL_B;
                          }
                          else if("BX" == capStr)
                          {
                              stackType = PAL_BX;
                          }
                          else if("E" == capStr)
                          {
                              stackType = PAL_E;
                          }
                          else if("EX" == capStr)
                          {
                              stackType = PAL_EX;
                          }
                          palletStackInfo[palletNum].stackType = stackType;
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                          capStr = rx.cap(4);
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                          capStr = rx.cap(5);
                          palletStackInfo[palletNum].stackName = capStr.toStdString();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      }

                  }
                  else if(fileInfoList[i].contains("TYPE"))
                  {
                      int palletType = 0;

                      QString pattern("\\s*(TYPE)\\s*(=)\\s*(\\w*)\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("TYPE" == rx.cap(1))
                      {
                          capStr = rx.cap(3);
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      }
                      if("PALLET" == capStr)
                      {
                          palletType = EM_STACK_PALLET;
                      }
                      else if("DEPALLET" == capStr)
                      {
                          palletType = EM_STACK_DEPALLET;
                      }

                      palletStackInfo[palletNum].stackUpDown = palletType;
                  }
                  else if(fileInfoList[i].contains("INCR"))
                  {
                      QString pattern("\\s*(INCR)\\s*(=)\\s*(\\w*)\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("INCR" == rx.cap(1))
                      {
                          capStr = rx.cap(3);
                          palletStackInfo[palletNum].execIncr = capStr.toInt();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      }
                  }
                  else if(fileInfoList[i].contains("PAL")&&(fileInfoList[i].contains("REG")))
                  {
                      QString pattern("\\s*(PAL)\\s*(REG)\\s*(=)\\s*(\\w*)\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("PAL" == rx.cap(1)
                              &&("REG" == rx.cap(2)))
                      {
                          capStr = rx.cap(4);
                          palletStackInfo[palletNum].stackRegisterNumber = capStr.toInt();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      }
                  }
                  else if(fileInfoList[i].contains("ORDER"))
                  {
                      QString pattern("\\s*(ORDER)\\s*(=)\\s*(\\w*)\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("ORDER" == rx.cap(1))
                      {
                          capStr = rx.cap(3);
                          palletStackInfo[palletNum].execOrder = capStr.toInt();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      }
                  }
                  else if(fileInfoList[i].contains("ROWS"))
                  {
                      QString pattern("\\s*(ROWS)\\s*(=)\\s*(\\[)\\s*(\\w*)\\s*(\\])\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("ROWS" == rx.cap(1))
                      {
                          capStr = rx.cap(4);
                          palletStackInfo[palletNum].row = capStr.toInt();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      }
                  }
                  else if(fileInfoList[i].contains("COLUMNS"))
                  {
                      QString pattern("\\s*(COLUMNS)\\s*(=)\\s*(\\[)\\s*(\\w*)\\s*(\\])\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("COLUMNS" == rx.cap(1))
                      {
                          capStr = rx.cap(4);
                          palletStackInfo[palletNum].col = capStr.toInt();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      }
                  }
                  else if(fileInfoList[i].contains("LAYERS"))
                  {
                      QString pattern("\\s*(LAYERS)\\s*(=)\\s*(\\[)\\s*(\\w*)\\s*(\\])\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("LAYERS" == rx.cap(1))
                      {
                          capStr = rx.cap(4);
                          palletStackInfo[palletNum].layer = capStr.toInt();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      }
                  }
                  else if(fileInfoList[i].contains("ROW_SPACE"))
                  {
                      QString pattern("\\s*(ROW_SPACE)\\s*(=)\\s*(\\d+)\\s*(:)\\s*(\\d+\\.?\\d*)\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("ROW_SPACE" == rx.cap(1))
                      {
                          capStr = rx.cap(3);
                          palletStackInfo[palletNum].intervalEnable[0] = capStr.toInt();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                          capStr = rx.cap(5);
                          palletStackInfo[palletNum].intervalValue[0] = capStr.toFloat();
                      }
                  }
                  else if(fileInfoList[i].contains("COLUMN_SPACE"))
                  {
                      QString pattern("\\s*(COLUMN_SPACE)\\s*(=)\\s*(\\d+)\\s*(:)\\s*(\\d+\\.?\\d*)\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("COLUMN_SPACE" == rx.cap(1))
                      {
                          capStr = rx.cap(3);
                          palletStackInfo[palletNum].intervalEnable[1] = capStr.toInt();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                          capStr = rx.cap(5);
                          palletStackInfo[palletNum].intervalValue[1] = capStr.toFloat();
                      }
                  }
                  else if(fileInfoList[i].contains("LAYER_SPACE"))
                  {
                      QString pattern("\\s*(LAYER_SPACE)\\s*(=)\\s*(\\d+)\\s*(:)\\s*(\\d+\\.?\\d*)\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("LAYER_SPACE" == rx.cap(1))
                      {
                          capStr = rx.cap(3);
                          palletStackInfo[palletNum].intervalEnable[2] = capStr.toInt();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                          capStr = rx.cap(5);
                          palletStackInfo[palletNum].intervalValue[2] = capStr.toFloat();
                      }
                  }
                  else if(fileInfoList[i].contains("AUXILIARY"))
                  {
                      int auxValue = 0;
                      QString pattern("\\s*(AUXILIARY)\\s*(POS)\\s*(=)\\s*(\\[)\\s*(\\w*)\\s*(\\])\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("AUXILIARY" == rx.cap(1)
                              &&("POS" == rx.cap(2)))
                      {
                          capStr = rx.cap(5);
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      }
                      if("YES" == capStr)
                      {
                          auxValue = EM_STACK_AUX_EXIST;
                      }
                      else if("NO" == capStr)
                      {
                          auxValue = EM_STACK_AUX_NONE;
                      }
                      palletStackInfo[palletNum].auxiliary = auxValue;
                  }
                  else if(fileInfoList[i].contains("APPR"))
                  {
                      QString pattern("\\s*(APPR)\\s*(=)\\s*(\\w*)\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("APPR" == rx.cap(1))
                      {
                          capStr = rx.cap(3);
                          palletStackInfo[palletNum].stackProximityCount = capStr.toInt();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      }
                  }
                  else if(fileInfoList[i].contains("RTRT"))
                  {
                      QString pattern("\\s*(RTRT)\\s*(=)\\s*(\\w*)\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("RTRT" == rx.cap(1))
                      {
                          capStr = rx.cap(3);
                          palletStackInfo[palletNum].stackFleeCount = capStr.toInt();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      }
                  }
                  else if(fileInfoList[i].contains("TEACH"))
                  {
                      QString pattern("\\s*(TEACH)\\s*(=)\\s*(\\d+)\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("TEACH" == rx.cap(1))
                      {
                          capStr = rx.cap(3);
                          palletStackInfo[palletNum].teachOrder = capStr.toInt();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      }
                  }
                  else if(fileInfoList[i].contains("BOTTOM:"))
                  {
  //                    qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**BOTTOM**"<<"i = "<<i<<endl;
                  }
                  else if((fileInfoList[i].contains("P [")) && (fileInfoList[i].contains(",")))
                  {
                      ++stackStyleSize;

                      int row = 0;
                      int col = 0;
                      int layer = 0;
                      QString pattern("\\s*(P)\\s*(\\[)\\s*(\\d+)\\s*(,)\\s*(\\d+)\\s*(,)\\s*(\\d+)\\s*(\\])\\s*(\\{)\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("P" == rx.cap(1)
                              &&("," == rx.cap(4))
                              && ("," == rx.cap(6)))
                      {
                          capStr = rx.cap(3);
                          row = capStr.toInt();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                          capStr = rx.cap(5);
                          col = capStr.toInt();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                          capStr = rx.cap(7);
                          layer = capStr.toInt();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      }


                      stackStyleNum = stackStyleSize - 1;

  //                    qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**P**"<<"i = "<<i<<endl;
                      palletStackInfo[palletNum].stackStylePointInfo.resize(stackStyleSize);
                      palletStackInfo[palletNum].stackStylePointInfo[stackStyleNum].rowColumnLayer.resize(3);
                      palletStackInfo[palletNum].stackStylePointInfo[stackStyleNum].rowColumnLayer[0] = row;
                      palletStackInfo[palletNum].stackStylePointInfo[stackStyleNum].rowColumnLayer[1] = col;
                      palletStackInfo[palletNum].stackStylePointInfo[stackStyleNum].rowColumnLayer[2] = layer;

                      /***********
                       * 测试使用
                       * *********/
                      regPlList[palletNum].row = row;
                      regPlList[palletNum].col = col;
                      regPlList[palletNum].layer = layer;
                  }
                  else if(fileInfoList[i].contains("[A_"))
                  {
                      ++apprSize;
                      apprNum = apprSize - 1;

                      palletStackInfo[palletNum].stackPointA_n.resize(apprSize);
                  }
                  else if(fileInfoList[i].contains("[BTM]"))
                  {
//                      qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**BTM**"<<"i = "<<i<<endl;
                  }
                  else if(fileInfoList[i].contains("[R_"))
                  {
                      ++fleeSize;
                      fleeNum = fleeSize - 1;
                      palletStackInfo[palletNum].stackPointR_n.resize(fleeSize);
//                      qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**R**"<<"i = "<<i<<endl;
                  }
                  else if(fileInfoList[i].contains("GP"))
                  {
                      pointPro.jointFlag = EM_CF_DEG_TYPE;

                      int groupNum = 1;
                      QString pattern("\\s*(GP)\\s*(\\d+)\\s*(:)(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("GP" == rx.cap(1))
                      {
                          capStr = rx.cap(2);
                          groupNum = capStr.toInt();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;

                      }
                      if((i > bottomList[palletNum]) && (i < routeList[palletNum]))
                      {
                          palletStackInfo[palletNum].stackStylePointInfo[stackStyleNum].stackPoint.groupNum = groupNum;
                      }
                      else if( (i > routeList[palletNum]) && (i < btmList[palletNum]))//2017.03.15 需改
                      {
                          palletStackInfo[palletNum].stackPointA_n[apprNum].groupNum = groupNum;
                      }
                      else if((i > btmList[palletNum]) && (i < btmEndList[palletNum]))//2017.03.15 需改
                      {
                          palletStackInfo[palletNum].stackPointBTM.groupNum = groupNum;
                      }
                      else if( i > btmEndList[palletNum])//2017.03.15 需改
                      {
                          palletStackInfo[palletNum].stackPointR_n[fleeNum].groupNum = groupNum;
                      }
//                        qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**GP**"<<"i = "<<i<<endl;
                  }
                  else if(fileInfoList[i].contains("UF") || fileInfoList[i].contains("UT"))
                  {
//                      qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**UF**"<<"i = "<<i<<endl;

                      QString pattern("\\s*(UF)\\s*(:)\\s*(\\w*)\\s*\\s*(,)\\s*(UT)\\s*(:)\\s*(\\w*)\\s*(,)\\s*(CONFIG)?\\s*(:)?\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);

                      int ufValue = 0;
                      int utValue = 0;
                      std::string conString;
                      if("UF" == rx.cap(1)
                              &&("UT" == rx.cap(5)))
                      {
                          capStr = rx.cap(3);
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                          ufValue = capStr.toInt();
                          capStr = rx.cap(7);
                          utValue = capStr.toInt();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                          capStr = rx.cap(11);
                          conString = capStr.toStdString();
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      }

                       if(i > bottomList[palletNum] && i < routeList[palletNum])
                       {

                           palletStackInfo[palletNum].stackStylePointInfo[stackStyleNum].stackPoint.ufValue = ufValue;
                           palletStackInfo[palletNum].stackStylePointInfo[stackStyleNum].stackPoint.utValue = utValue;
                           palletStackInfo[palletNum].stackStylePointInfo[stackStyleNum].stackPoint.configString = conString;
                       }
                       else if( (i > routeList[palletNum]) && (i < btmList[palletNum]))
                       {
                           palletStackInfo[palletNum].stackPointA_n[apprNum].ufValue = ufValue;
                           palletStackInfo[palletNum].stackPointA_n[apprNum].utValue = utValue;
                           palletStackInfo[palletNum].stackPointA_n[apprNum].configString = conString;
//                             palletStackInfo[palletNum].stackPointA_n[apprNum].direction = direct;
                       }
                       //else if((i > btmList[palletNum]) && (i < (btmList[palletNum] + 5)))
                       else if((i > btmList[palletNum]) && (i < btmEndList[palletNum]))//2017.03.15 需改
                       {
                           palletStackInfo[palletNum].stackPointBTM.ufValue = ufValue;
                           palletStackInfo[palletNum].stackPointBTM.utValue = utValue;
                           palletStackInfo[palletNum].stackPointBTM.configString = conString;
//                             palletStackInfo[palletNum].stackPointBTM.direction = direct;
                       }
                       else if( i > btmEndList[palletNum] )//2017.03.15 需改
                       {
                           palletStackInfo[palletNum].stackPointR_n[fleeNum].ufValue = ufValue;
                           palletStackInfo[palletNum].stackPointR_n[fleeNum].utValue = utValue;
                           palletStackInfo[palletNum].stackPointR_n[fleeNum].configString = conString;
//                             palletStackInfo[palletNum].stackPointR_n[fleeNum].direction = direct;
                       }
//                       qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**UF**"<<"i = "<<i<<endl;
                  }
                  else if(fileInfoList[i].contains('X')||(fileInfoList[i].contains('Y'))||(fileInfoList[i].contains('Z')))
                  {
                      pointPro.jointFlag = EM_CF_WORLD_TYPE;

                      QString pattern("\\s*(X)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(mm)\\s*(,)\\s*(Y)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(mm)\\s*(,)\\s*(Z)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(mm)\\s*(.*)");
                      //QString pattern("\\s*(X)\\s*(=)\\s*(\\d+.?\\d+)\\s*(mm)\\s*(,)\\s*(Y)\\s*(=)\\s*(\\d+.?\\d+)\\s*(mm)\\s*(,)\\s*(Z)\\s*(=)\\s*(\\d+.?\\d+)\\s*(mm)\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("X" == rx.cap(1)
                              &&("Y" == rx.cap(6))
                              &&("Z" == rx.cap(11)))
                      {
                          capStr = rx.cap(3);
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                          worldValue.append(capStr.toFloat());
                          capStr = rx.cap(8);
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                          worldValue.append(capStr.toFloat());
                          capStr = rx.cap(13);
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                          worldValue.append(capStr.toFloat());
                      }
                  }
                  else if(fileInfoList[i].contains('W')||(fileInfoList[i].contains('P'))||(fileInfoList[i].contains('R')))
                  {
                      pointPro.jointFlag = EM_CF_WORLD_TYPE;
                      QString pattern("\\s*(W)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(deg)\\s*(,)\\s*(P)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(deg)\\s*(,)\\s*(R)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(deg)\\s*(.*)");
                      //QString pattern("\\s*(W)\\s*(=)\\s*(\\d+.?\\d+)\\s*(deg)\\s*(,)\\s*(P)\\s*(=)\\s*(\\d+.?\\d+)\\s*(deg)\\s*(,)\\s*(R)\\s*(=)\\s*(\\d+.?\\d+)\\s*(deg)\\s*(.*)");
                      QRegExp rx(pattern);
                      str.indexOf(rx);
                      if("W" == rx.cap(1)
                              &&("P" == rx.cap(6))
                              &&("R" == rx.cap(11)))
                      {
                          capStr = rx.cap(3);
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                          worldValue.append(capStr.toFloat());
                          capStr = rx.cap(8);
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                          worldValue.append(capStr.toFloat());
                          capStr = rx.cap(13);
//                          qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                          worldValue.append(capStr.toFloat());
                      }
                  }
                  else if(fileInfoList[i].contains("J"))
                  {
                        QString pattern1("\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");
                        QString pattern2("\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");
                        QString pattern3("\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");

      //                  QString pattern("\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,){1,3}(.*)");
                        QRegExp rx1(pattern1);
                        QRegExp rx2(pattern2);
                        QRegExp rx3(pattern3);
                        //str.indexOf(rx);
                        QString str = fileInfoList[i];

                        bool match;
                        if((match = rx1.exactMatch(str)) == true)
                        {
                            capStr = rx1.cap(4);
//                            qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                            worldValue.append(capStr.toFloat());

                            capStr = rx1.cap(10);
//                            qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                            worldValue.append(capStr.toFloat());

                            capStr = rx1.cap(16);
//                            qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                            worldValue.append(capStr.toFloat());
                        }
                        else if((match = rx2.exactMatch(str)) == true)
                        {
                            capStr = rx2.cap(4);
//                            qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                            worldValue.append(capStr.toFloat());

                            capStr = rx2.cap(10);
//                            qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                            worldValue.append(capStr.toFloat());
                        }
                        else if((match = rx3.exactMatch(str)) == true)
                        {
                            capStr = rx3.cap(4);
//                            qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                            worldValue.append(capStr.toFloat());
                        }

                  }
                  else if(fileInfoList[i].contains("E") && (fileInfoList[i].contains(",")))//2017.03.14
                  {
//                      qDebug()<<"E  "<<i;
                        QString pattern1("\\s*(E)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(E)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(E)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");
                        QString pattern2("\\s*(E)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(E)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");
                        QString pattern3("\\s*(E)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");

                        QRegExp rx1(pattern1);
                        QRegExp rx2(pattern2);
                        QRegExp rx3(pattern3);
                        //str.indexOf(rx);
                        QString str = fileInfoList[i];

                        bool match;
                        if((match = rx1.exactMatch(str)) == true)
                        {
                            capStr = rx1.cap(4);
//                            qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                            extWorldValue.append(capStr.toFloat());

                            capStr = rx1.cap(10);
//                            qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                            extWorldValue.append(capStr.toFloat());

                            capStr = rx1.cap(16);
//                            qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                            extWorldValue.append(capStr.toFloat());
                        }
                        else if((match = rx2.exactMatch(str)) == true)
                        {
                            capStr = rx2.cap(4);
//                            qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                            extWorldValue.append(capStr.toFloat());

                            capStr = rx2.cap(10);
//                            qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                            extWorldValue.append(capStr.toFloat());
                        }
                        else if((match = rx3.exactMatch(str)) == true)
                        {
                            capStr = rx3.cap(4);
//                            qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                            extWorldValue.append(capStr.toFloat());
                        }
                  }
                  else if(fileInfoList[i].contains("};"))
                  {
//                      qDebug() << "***pointPro**"<<worldValue<<endl;
//                      qDebug() << "***ext pointPro**"<<extWorldValue<<endl;
//                      qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**UF**"<<"i = "<<i<<"**palletNum**"<<palletNum<<endl;
                      if(i > bottomList[palletNum] && i < routeList[palletNum])
                      {
                          //2017.05.24 补充 码垛点数量的初始化
                          if(5 != palletStackInfo[palletNum].stackStylePointInfo[stackStyleNum].stackPoint.positionValue.size())
                          {
                              palletStackInfo[palletNum].stackStylePointInfo[stackStyleNum].stackPoint.positionValue.resize(5);
                          }

//                          qDebug() << "***     stackStylePointInfo";
                          //2017.05.24 此处有问题 如果有列点没有行点,读文件后列点会变成行点
                          palletStackInfo[palletNum].stackStylePointInfo[stackStyleNum].stackPoint.positionValue.resize(worldValue.size());
                          palletStackInfo[palletNum].stackStylePointInfo[stackStyleNum].stackPoint.positionValue = worldValue.toStdVector();
                          palletStackInfo[palletNum].stackStylePointInfo[stackStyleNum].stackPoint.extPositionValue.resize(extWorldValue.size());
                          palletStackInfo[palletNum].stackStylePointInfo[stackStyleNum].stackPoint.extPositionValue = extWorldValue.toStdVector();

                          int direct = 0;

                          palletStackInfo[palletNum].stackStylePointInfo[stackStyleNum].stackPoint.jointFlag = pointPro.jointFlag;
                          palletStackInfo[palletNum].stackStylePointInfo[stackStyleNum].stackPoint.recordStatus = direct;
//                            qDebug() << "****i**"<<i<<"***pallet***"<<palletNum<<"***stackStyleNum****"<<stackStyleNum<<
//                                        "****m_fW***"<<worldValue<<endl;
                      }
                      else if( (i > routeList[palletNum]) && (i < btmList[palletNum]))
                      {
                          palletStackInfo[palletNum].stackPointA_n[apprNum].positionValue.resize(worldValue.size());
                          palletStackInfo[palletNum].stackPointA_n[apprNum].positionValue = worldValue.toStdVector();
                          palletStackInfo[palletNum].stackPointA_n[apprNum].extPositionValue.resize(extWorldValue.size());
                          palletStackInfo[palletNum].stackPointA_n[apprNum].extPositionValue = extWorldValue.toStdVector();
                          int direct = 0;

                          palletStackInfo[palletNum].stackPointA_n[apprNum].recordStatus = direct;
                          palletStackInfo[palletNum].stackPointA_n[apprNum].jointFlag = pointPro.jointFlag;//2017.03.24补充 不添加的话没有点的类型数据
//                            qDebug() << "****i**"<<i<<"***pallet***"<<palletNum<<"***apprNum****"<<apprNum<<
//                                        "****m_fW***"<<worldValue<<endl;
//                          qDebug() << "***     stackPointA_n";

//                          qDebug()<<"stack index:"<<palletNum;
//                          qDebug()<<"A Point index:"<<apprNum;
//                          for(int i = 0;i<palletStackInfo[palletNum].stackPointA_n[apprNum].positionValue.size();i++)
//                          {
//                              qDebug()<<"A Point pos:"<<palletStackInfo[palletNum].stackPointA_n[apprNum].positionValue[i];
//                          }
//                          for(int i = 0;i<palletStackInfo[palletNum].stackPointA_n[apprNum].extPositionValue.size();i++)
//                          {
//                              qDebug()<<"A Point ex pos:"<<palletStackInfo[palletNum].stackPointA_n[apprNum].extPositionValue[i];
//                          }
                      }
                      else if((i > btmList[palletNum]) && (i < (btmEndList[palletNum] + 1)))//2017.03.15 需改
                      {
                          palletStackInfo[palletNum].stackPointBTM.positionValue.resize(worldValue.size());
                          palletStackInfo[palletNum].stackPointBTM.positionValue = worldValue.toStdVector();
                          palletStackInfo[palletNum].stackPointBTM.extPositionValue.resize(extWorldValue.size());
                          palletStackInfo[palletNum].stackPointBTM.extPositionValue = extWorldValue.toStdVector();
                          int direct = 0;

                          palletStackInfo[palletNum].stackPointBTM.recordStatus = direct;
                          palletStackInfo[palletNum].stackPointBTM.jointFlag = pointPro.jointFlag;
//                            qDebug() << "****i**"<<i<<"***pallet***"<<palletNum<<"***stackPointBTM****"<<
//                                        "****m_fW***"<<worldValue<<endl;
//                          qDebug() << "***     stackPointBTM";
                      }
                      //else if( i > (btmEndList[palletNum] + 6))//2017.03.15 需改
                      else if( i > btmEndList[palletNum])//2017.03.28 需改
                      {
                          palletStackInfo[palletNum].stackPointR_n[fleeNum].positionValue.resize(worldValue.size());
                          palletStackInfo[palletNum].stackPointR_n[fleeNum].positionValue = worldValue.toStdVector();
                          palletStackInfo[palletNum].stackPointR_n[fleeNum].extPositionValue.resize(extWorldValue.size());
                          palletStackInfo[palletNum].stackPointR_n[fleeNum].extPositionValue = extWorldValue.toStdVector();
                          int direct = 0;

                          palletStackInfo[palletNum].stackPointR_n[fleeNum].recordStatus = direct;
                          palletStackInfo[palletNum].stackPointR_n[fleeNum].jointFlag = pointPro.jointFlag;
//                            qDebug() << "****i**"<<i<<"***pallet***"<<palletNum<<"***fleeNum****"<<fleeNum<<
//                                        "****m_fW***"<<worldValue<<endl;
//                          qDebug() << "***     stackPointR_n";

//                          qDebug()<<"stack index:"<<palletNum;
//                          qDebug()<<"R Point index:"<<fleeNum;
//                          for(int i = 0;i<palletStackInfo[palletNum].stackPointR_n[fleeNum].positionValue.size();i++)
//                          {
//                              qDebug()<<"R Point pos:"<<palletStackInfo[palletNum].stackPointR_n[fleeNum].positionValue[i];
//                          }
//                          for(int i = 0;i<palletStackInfo[palletNum].stackPointR_n[fleeNum].extPositionValue.size();i++)
//                          {
//                              qDebug()<<"R Point ex pos:"<<palletStackInfo[palletNum].stackPointR_n[fleeNum].extPositionValue[i];
//                          }
                      }
                      worldValue.clear();
                      extWorldValue.clear();
                  }
                  else if(fileInfoList[i].contains("ROUTE:"))
                  {
                      palletStackInfo[palletNum].stackStyleCount =  stackStyleSize;
                      stackStyleSize = 0;
                  }
//                qDebug() <<__FUNCTION__<<"*****"<<__LINE__<<"**UF**"<<"i = "<<i<<endl;
              }

              //2017.05.24 补救措施 对每个码垛的内容进行补充处理
              QVector<StackStylePointInfo > tmpStackPointInfo;
              for(int i = 0;i < palletStackInfo.size();i++)
              {
                  tmpStackPointInfo.clear();//清空容器
                  //qDebug()<<"orign size::"<<palletStackInfo[i].stackStylePointInfo.size();

                  if(palletStackInfo[i].stackStylePointInfo.size() > 1 &&
                          palletStackInfo[i].stackStylePointInfo.size() < 5)
                  {
                      for(int j = 0;j<palletStackInfo[i].stackStylePointInfo.size();j++)
                      {
                          tmpStackPointInfo.append(palletStackInfo[i].stackStylePointInfo[j]);
                          qDebug()<<tmpStackPointInfo[j].rowColumnLayer[0]<<tmpStackPointInfo[j].rowColumnLayer[1]<<tmpStackPointInfo[j].rowColumnLayer[2];
                      }
                      //qDebug()<<"tmp size::"<<palletStackInfo[i].stackStylePointInfo.size();

                      //重新排序
                      palletStackInfo[i].stackStylePointInfo.resize(5);
                      for(int j = 1;j<5;j++)
                      {
                          palletStackInfo[i].stackStylePointInfo[j] = tmpStackPointInfo[0];
                      }
                      //原点,没有改变位置因此不需要再去赋值了
                      //palletStackInfo[i].stackStylePointInf[0] = tmpStackPointInfo[j].rowColumnLayer[0];
                      //其他点
                      for(int j = 1;j<tmpStackPointInfo.size();j++)
                      {
                          if(tmpStackPointInfo[j].rowColumnLayer[0] > 1)//row
                          {
                              if(tmpStackPointInfo[j].rowColumnLayer[1] > 1)
                              {
                                  qDebug()<<"this is a help";
                                  //这是一个辅助点
                                  palletStackInfo[i].stackStylePointInfo[4] = tmpStackPointInfo[j];
                              }
                              else
                              {
                                  //这是一个普通的行点
                                  qDebug()<<"this is a row";
                                  palletStackInfo[i].stackStylePointInfo[1] = tmpStackPointInfo[j];
                              }

                              continue;//判断下一个
                          }
                          else if(tmpStackPointInfo[j].rowColumnLayer[1] > 1)//col
                          {
                              qDebug()<<"this is a col";
                              palletStackInfo[i].stackStylePointInfo[2] = tmpStackPointInfo[j];
                              continue;//判断下一个
                          }
                          else if(tmpStackPointInfo[j].rowColumnLayer[2] > 1)//lay
                          {
                              qDebug()<<"this is a lay";
                              palletStackInfo[i].stackStylePointInfo[3] = tmpStackPointInfo[j];
                              continue;//判断下一个
                          }
                      }
                  }
                  else if(5 == palletStackInfo[i].stackStylePointInfo.size() ||
                          1 == palletStackInfo[i].stackStylePointInfo.size())
                  {
                      //只有1个或者全有的情况下不需要做排序判断了
                      continue;
                  }

                  //qDebug()<<"after size::"<<palletStackInfo[i].stackStylePointInfo.size();
              }
          }

          qDebug()<<"*******************commandStart "<<commandStart + 1;
          qDebug()<<"******positionStart "<<positionStart<<" ** endline ** "<<endLine;
          qDebug()<<"*******************fileInfoList.size "<<fileInfoList.size();
          for(int i = commandStart + 1; i < positionStart;i++)
          {
//              if(ENUM_COMMAND_RESET == *engineStatus)
//              {
//                  return 1;
//              }
//              if((positionStart - commandStart -1) != fileInfoList.size())//有问题
//              {
//                  return 1;
//              }
              QString str = fileInfoList[i];
              QString pattern1("\\s*(\\d+)\\s*(:)\\s*(.*)");
              QString pattern2("\\s*(\\/\\/)\\s*(.*)");
              QRegExp rx1(pattern1);
              QRegExp rx2(pattern2);

              str.indexOf(rx1);
              str.indexOf(rx2);
              if(":" == rx1.cap(2))
              {
                  capStr = rx1.cap(1);
//                  qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  capStr = rx1.cap(3);
                  cmdStrList.append(capStr);
//                  qDebug()<<__LINE__<<"*******"<<capStr<<endl;
              }
              else if("//" == rx2.cap(1))
              {
                  capStr = str;
//                  qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  cmdStrList.append(capStr);
              }
              else//2017-03-23 缺少行编号,正常读取,但是会有会控制器的报错提示
              {
                  capStr = str;
//                  qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  cmdStrList.append(capStr);
              }
          }
          for(int i = positionStart + 1;i < endLine;i++)
          {
//              if(ENUM_COMMAND_RESET == *engineStatus)
//              {
//                  return 1;
//              }
              if(i < 0)
              {
                  qDebug()<<"read file wrong";
                  break;
              }
              QString str = fileInfoList[i];
              if(fileInfoList[i].contains("P["))
              {
                  QString pattern("\\s*(P)\\s*(\\[)\\s*(\\d+)\\s*(\\])\\s*(\\{)\\s*(.*)");
                  QRegExp rx(pattern);
                  str.indexOf(rx);
                  if("P" == rx.cap(1)
                          &&("[" == rx.cap(2))
                          &&("]" == rx.cap(4)))
                  {
                      capStr = rx.cap(3);
                      pointPro.pointNum = capStr.toInt();
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  }
              }
              else if(fileInfoList[i].contains("GP"))
              {
                  pointPro.jointFlag = EM_CF_DEG_TYPE;
                  QString pattern("\\s*(GP)\\s*(\\d+)\\s*(:)(.*)");
                  QRegExp rx(pattern);
                  str.indexOf(rx);
                  if("GP" == rx.cap(1))
                  {
                      capStr = rx.cap(2);
                      pointPro.groupNum = capStr.toInt();
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  }
              }
              else if(fileInfoList[i].contains("UF") || fileInfoList[i].contains("UT"))
              {
                  QString pattern("\\s*(UF)\\s*(:)\\s*(\\w*)\\s*\\s*(,)\\s*(UT)\\s*(:)\\s*(\\w*)\\s*(,)\\s*(CONFIG)?\\s*(:?)\\s*(.*)");
                  QRegExp rx(pattern);
                  str.indexOf(rx);

//                  qDebug() << __LINE__ << "====="<<rx.cap(1)<<"===="<<rx.cap(5)<<"\n\n\n";

                  if("UF" == rx.cap(1) && ("UT" == rx.cap(5)))
                  {
                      capStr = rx.cap(3);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      pointPro.ufValue = capStr.toInt();
                      capStr = rx.cap(7);
                      pointPro.utValue = capStr.toInt();
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      capStr = rx.cap(11);
                      pointPro.configString = capStr.toStdString();
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                  }
              }
              else if(fileInfoList[i].contains("J"))
              {
//                  QString pattern("\\s*(J)\\s*(\\d+)\\s*(=)\\s*(\\d+.?\\d+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(J)\\s*(\\d+)\\s*(=)\\s*(\\d+.?\\d+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(J)\\s*(\\d+)\\s*(=)\\s*(\\d+.?\\d+)\\s*([mmdeg]{2,3})\\s*(.*)");
//                  QRegExp rx(pattern);
//                  str.indexOf(rx);
//                  if("J" == rx.cap(1)&&("=") == rx.cap(3))
//                  {
//                      capStr = rx.cap(4);
//                      qDebug()<<__LINE__<< "*******" <<capStr<<endl;
//                      pointPro.positionValue.push_back(capStr.toFloat());
//                      capStr = rx.cap(10);
//                      qDebug()<<__LINE__<< "*******" <<capStr<<endl;
//                      pointPro.positionValue.push_back(capStr.toFloat());
//                      capStr = rx.cap(16);
//                      qDebug()<<__LINE__<< "*******" <<capStr<<endl;
//                      pointPro.positionValue.push_back(capStr.toFloat());
//                  }

                  QString pattern1("\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");
                  QString pattern2("\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");
                  QString pattern3("\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");

//                  QString pattern("\\s*(J)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,){1,3}(.*)");
                  QRegExp rx1(pattern1);
                  QRegExp rx2(pattern2);
                  QRegExp rx3(pattern3);
                  //str.indexOf(rx);
                  QString str = fileInfoList[i];

                  bool match;
                  if((match = rx1.exactMatch(str)) == true)
                  {
                      capStr = rx1.cap(4);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      pointPro.positionValue.push_back(capStr.toFloat());

                      capStr = rx1.cap(10);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      pointPro.positionValue.push_back(capStr.toFloat());

                      capStr = rx1.cap(16);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      pointPro.positionValue.push_back(capStr.toFloat());
                  }
                  else if((match = rx2.exactMatch(str)) == true)
                  {
                      capStr = rx2.cap(4);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      pointPro.positionValue.push_back(capStr.toFloat());

                      capStr = rx2.cap(10);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      pointPro.positionValue.push_back(capStr.toFloat());
                  }
                  else if((match = rx3.exactMatch(str)) == true)
                  {
                      capStr = rx3.cap(4);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      pointPro.positionValue.push_back(capStr.toFloat());
                  }

              }
              else if(fileInfoList[i].contains('X')||(fileInfoList[i].contains('Y'))||(fileInfoList[i].contains('Z')))
              {
                  QString pattern("\\s*(X)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(mm)\\s*(,)\\s*(Y)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(mm)\\s*(,)\\s*(Z)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(mm)\\s*(.*)");
//                  QString pattern("\\s*(X)\\s*(=)\\s*(\\d+.?\\d+)\\s*(mm)\\s*(,)\\s*(Y)\\s*(=)\\s*(\\d+.?\\d+)\\s*(mm)\\s*(,)\\s*(Z)\\s*(=)\\s*(\\d+.?\\d+)\\s*(mm)\\s*(.*)");
                  QRegExp rx(pattern);
                  str.indexOf(rx);
                  if("X" == rx.cap(1)
                          &&("Y" == rx.cap(6))
                          &&("Z" == rx.cap(11)))
                  {
                      capStr = rx.cap(3);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      pointPro.positionValue.push_back(capStr.toFloat());
                      capStr = rx.cap(8);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      pointPro.positionValue.push_back(capStr.toFloat());
                      capStr = rx.cap(13);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      pointPro.positionValue.push_back(capStr.toFloat());
                  }

                  pointPro.jointFlag = EM_CF_WORLD_TYPE;
              }
              else if(fileInfoList[i].contains('W')||(fileInfoList[i].contains('P'))||(fileInfoList[i].contains('R')))
              {
//    QString pattern("\\s*(W)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(deg)\\s*(,)\\s*(P)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(deg)\\s*(,)\\s*(R)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(deg)\\s*(.*)");
                  QString pattern("\\s*(W)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(deg)\\s*(,)\\s*(P)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(deg)\\s*(,)\\s*(R)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*(deg)\\s*(.*)");
                  QRegExp rx(pattern);
                  str.indexOf(rx);
                  if("W" == rx.cap(1)
                          &&("P" == rx.cap(6))
                          &&("R" == rx.cap(11)))
                  {
                      capStr = rx.cap(3);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      pointPro.positionValue.push_back(capStr.toFloat());
                      capStr = rx.cap(8);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      pointPro.positionValue.push_back(capStr.toFloat());
                      capStr = rx.cap(13);
//                      qDebug()<<__LINE__<<"*******"<<capStr<<endl;
                      pointPro.positionValue.push_back(capStr.toFloat());
                  }
                  pointPro.jointFlag = EM_CF_WORLD_TYPE;
              }
              else if(fileInfoList[i].contains('E'))    //外部轴判断部分
              {
                  QString pattern1("\\s*(E)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(E)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(E)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");
                  QString pattern2("\\s*(E)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,)\\s*(E)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");
                  QString pattern3("\\s*(E)\\s*(\\d+)\\s*(=)\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*([mmdeg]{2,3})\\s*(,?)\\s*(.*)");

                  QRegExp rx1(pattern1);
                  QRegExp rx2(pattern2);
                  QRegExp rx3(pattern3);
                  //str.indexOf(rx);
                  QString str = fileInfoList[i];
//                  qDebug()<<__LINE__<<"ex*******"<<str<<endl;

                  bool match;
                  if((match = rx1.exactMatch(str)) == true)
                  {
                      capStr = rx1.cap(4);
//                      qDebug()<< pointPro.pointNum <<" rx1*******"<<capStr<<endl;
                      pointPro.extPositionValue.push_back(capStr.toFloat());

                      capStr = rx1.cap(10);
//                      qDebug()<< pointPro.pointNum <<" rx1*******"<<capStr<<endl;
                      pointPro.extPositionValue.push_back(capStr.toFloat());

                      capStr = rx1.cap(16);
//                      qDebug()<< pointPro.pointNum <<" rx1*******"<<capStr<<endl;
                      pointPro.extPositionValue.push_back(capStr.toFloat());
                  }
                  else if((match = rx2.exactMatch(str)) == true)
                  {
                      capStr = rx2.cap(4);
//                      qDebug()<< pointPro.pointNum <<" rx2*******"<<capStr<<endl;
                      pointPro.extPositionValue.push_back(capStr.toFloat());

                      capStr = rx2.cap(10);
//                      qDebug()<< pointPro.pointNum <<" rx2*******"<<capStr<<endl;
                      pointPro.extPositionValue.push_back(capStr.toFloat());
                  }
                  else if((match = rx3.exactMatch(str)) == true)
                  {
                      capStr = rx3.cap(4);
//                      qDebug()<< pointPro.pointNum <<" rx3*******"<<capStr<<endl;
                      pointPro.extPositionValue.push_back(capStr.toFloat());
                  }
              }
              else if(fileInfoList[i].contains("};"))
              {
                  getPointProList.push_back(pointPro);
                  pointPro.positionValue.clear();       //清空
                  pointPro.extPositionValue.clear();    //清空
              }
          }
       }
        else
        {}
        file.close();
    }

    qDebug()<<"readProgram ======= read END";

    readAllowFlag = true;

//    qDebug()<<"getPointProList.size()"<<getPointProList.size();
//    for(int z = 0;z<getPointProList.size();z++)
//    {
//        //int  index = getPointProList.size()-1;
//        qDebug()<<"num = "<<getPointProList[z].pointNum;
//        QVector<float> tmp;
//        for(int k = 0;k<getPointProList[z].positionValue.size();k++)
//        {
//            tmp.append(getPointProList[z].positionValue[k]);
//        }
//        qDebug()<<tmp;
//        tmp.clear();
//        for(int k = 0;k<getPointProList[z].extPositionValue.size();k++)
//        {
//            tmp.append(getPointProList[z].extPositionValue[k]);
//        }
//        qDebug()<<tmp;
//    }

    return 0;
}


void FileData::writeProgramFile(QString strFilePath,bool fileExist)
{

//    //point test
//    qDebug()<<"start "<<getPointProList.size();
//    for(int i = 0;i<getPointProList.size();i++)
//    {
//        qDebug()<<i<<":"<<getPointProList[i].pointNum;
//    }

    //qDebug()<<fileExist;

    QVector <QString> tmpUnit;//单位数据 缓存
    tmpUnit.clear();//暂时先修改普通P点的单位 码垛未修改
    for(int j = 0; j < D_ROBOT_AXIS_MAX;j++)//点数据最多是D_ROBOT_AXIS_MAX个
    {
        if(j<saveAxisUnit.size())//实际有的轴 eg 4个
        {
            if(saveAxisUnit[j] == EM_AXIS_DEG)
            {
                tmpUnit.append("deg,");
            }
            else
            {
                tmpUnit.append("mm,");
            }
        }
        else
        {
            tmpUnit.append("mm,");
        }
    }//tmpUnit.size = 6 后面使用的时候,需要判断是否 <= 6

    programList.clear();

    QString programString;
    programString = "/PROG";
    programList.append(programString);
    programString = "/ATTR";
    programList.append(programString);
    programString = "OWNER  =";
    programString = programString + QString::fromStdString(fileProInfo.owner) + ";";
    programList.append(programString);
    programString = "COMMENT  =";
    programString = programString + QString::fromStdString(fileProInfo.comment) + ";";
    programList.append(programString);
    programString = "PROG_SIZE  =";
    programString = programString + QString::number(0) + ";";
    programList.append(programString);
    programString = "CREATE  =";
    programString = programString + QString::fromStdString(fileProInfo.createTime) + ";";
    programList.append(programString);
    programString = "MODIFIED  =";
    programString = programString + QString::fromStdString(fileProInfo.modifiTime) + ";";
    programList.append(programString);
    programString = "FILE_NAME  =";
    programString = programString + QString::fromStdString(fileProInfo.fileName) + ";";
    programList.append(programString);
    programString = "VERSION  =";
    programString = programString + QString::fromStdString(fileProInfo.version) + ";";
    programList.append(programString);
    programString = "LINE_COUNT  =";
    programString = programString + QString::number(cmdStrWriteList.size()) + ";";//此处原本为控制器接收后的指令长度(即要保存的缓存长度)
    programList.append(programString);
    programString = "MEMORY_SIZE  =";
    programString = programString + QString::number(0) + ";";
    programList.append(programString);
    programString = "PROTECT  =";
    programString = programString + "READ_WRITE;";
    programList.append(programString);
    programString = "TEMPLATETYPE  =";
    programString = programString + QString::number(fileProInfo.templateType) + ";";
    programList.append(programString);
    programString = "TCD: STACK_SIZE  =";
    programString = programString + QString::number(0) + ",";
    programList.append(programString);
    programString = "TASK_PRIORITY  =";
    programString = programString + QString::number(0) + ",";
    programList.append(programString);
    programString = "TIME_SLICE  =";
    programString = programString + QString::number(0) + ",";
    programList.append(programString);
    programString = "BUSY_LAMP_OFF  =";
    programString = programString + QString::number(0) + ",";
    programList.append(programString);
    programString = "ABORT_REQUEST  =";
    programString = programString + QString::number(0) + ",";
    programList.append(programString);
    programString = "PAUSE_REQUEST  =";
    programString = programString + QString::number(0) + ";";
    programList.append(programString);
    programString = "DEFAULT_GROUP  =";
    programString = programString + ";";
    programList.append(programString);
    programString = "CONTROL_CODE  =";
    programString = programString + ";";
    programList.append(programString);
    programString = "/APPL";
    programList.append(programString);

//#if ok
    qDebug()<< __FUNCTION__<<"*****"<<__LINE__<<"***palletStackInfo size****"<<palletStackInfo.size()<<endl;
    if(palletStackInfo.size())
    {
        int tempType,tempStackNum,tempStackUpDown,tempExecIncr,
                tempStackReg,tempExecOrder,tempTeach,tempRow,tempCol,
                tempLayer,tempAux,tempApprNum,tempFleeNum,row,
                col,layer;

        QVector <int > tempIntervalEnable;//是否有间距距离
        QVector <float > tempIntervalValue;//间距距离

        QString tempName,conString;

//        float xValue,yValue,zValue,wValue,pValue,rValue;
        float jointAngle;

        //int direction = 0;

        for(int i = 0; i < palletStackInfo.size();i++)
        {
            programString = "Palletizing["+QString::number(i + 1) + "];";
            programList.append(programString);
            programString = "   CONFIG:";
            programList.append(programString);

            tempType = palletStackInfo[i].stackType;
            tempStackNum = palletStackInfo[i].stackNumber;
            tempName = QString::fromStdString(palletStackInfo[i].stackName);
            tempStackUpDown = palletStackInfo[i].stackUpDown;
            tempExecIncr = palletStackInfo[i].execIncr;
            tempStackReg = palletStackInfo[i].stackRegisterNumber;
            tempExecOrder = palletStackInfo[i].execOrder;
            tempTeach = palletStackInfo[i].teachOrder;
            tempRow = palletStackInfo[i].row;
            tempCol = palletStackInfo[i].col;
            tempLayer = palletStackInfo[i].layer;
            tempAux = palletStackInfo[i].auxiliary;
            tempApprNum = palletStackInfo[i].stackProximityCount;
            tempFleeNum = palletStackInfo[i].stackFleeCount;

            for(int j = 0;j < 3;j++)//强制初始化3个
            {
                if(j < palletStackInfo[i].intervalEnable.size())//防止数据超过3个或者不足3个
                {
                    tempIntervalEnable.append(palletStackInfo[i].intervalEnable[j]);
                }
                else
                {
                    tempIntervalEnable.append(0);
                }

                if(j < palletStackInfo[i].intervalValue.size())
                {
                    tempIntervalValue.append(palletStackInfo[i].intervalValue[j]);
                }
                else
                {
                    tempIntervalValue.append(0.00);
                }
            }

//            qDebug()<< __FUNCTION__<<"*****"<<__LINE__<<endl;

            if(tempType == PAL_B)
            {
                programString = "       PALLETIZING-B_" + QString::number(tempStackNum) + " "+ tempName + ";";
            }
            else if(tempType == PAL_BX)
            {
                programString = "       PALLETIZING-BX_" + QString::number(tempStackNum) + " "+ tempName + ";";
            }
            else if(tempType == PAL_E)
            {
                programString = "       PALLETIZING-E_" + QString::number(tempStackNum) + " "+ tempName + ";";
            }
            else if(tempType == PAL_EX)
            {
                programString = "       PALLETIZING-EX_" + QString::number(tempStackNum) + " "+ tempName + ";";
            }
            programList.append(programString);
            if(tempStackUpDown == EM_STACK_PALLET)
            {
                programString = "       TYPE = PALLET;";
            }
            else if(tempStackUpDown == EM_STACK_DEPALLET)
            {
                programString = "       TYPE = DEPALLET;";
            }
            programList.append(programString);
            programString = "       INCR = " + QString::number(tempExecIncr) + ";";
            programList.append(programString);
            programString = "       PAL REG = " + QString::number(tempStackReg) + ";";
            programList.append(programString);
            if(tempExecOrder == EM_ORDER_RCL)
            {
                programString = "       ORDER = RCL;";
            }
            else if(tempExecOrder == EM_ORDER_CRL)
            {
                programString = "       ORDER = CRL;";
            }
            programList.append(programString);
            programString = "       ROWS = [" + QString::number(tempRow) + "];";
            programList.append(programString);
            programString = "       COLUMNS = [" +QString::number(tempCol) + "];";
            programList.append(programString);
            programString = "       LAYERS = [" + QString::number(tempLayer) + "];";
            programList.append(programString);
            if(tempAux == EM_STACK_AUX_EXIST)
            {
                programString = "       AUXILIARY POS = [YES ];";
            }
            else if(tempAux == EM_STACK_AUX_NONE)
            {
                programString = "       AUXILIARY POS = [NO ];";
            }
            programList.append(programString);
            programString = "       APPR = "+QString::number(tempApprNum) + ";";
            programList.append(programString);
            programString = "       RTRT = " +QString::number(tempFleeNum) +";";
            programList.append(programString);
            if(tempTeach == 0)
            {
                programString = "       TEACH = 0;";
            }
            else
            {
                programString = "       TEACH = 1;";
            }
//            qDebug()<< __FUNCTION__<<"*****"<<__LINE__<<endl;
            programList.append(programString);

            //2017.03.29 新添加字段
            programString = "       ROW_SPACE = " + QString::number(tempIntervalEnable[0]) + " :" + QString::number(tempIntervalValue[0]) + "mm;";
            programList.append(programString);
            programString = "       COLUMN_SPACE = " + QString::number(tempIntervalEnable[1]) +  " :" + QString::number(tempIntervalValue[1]) + "mm;";
            programList.append(programString);
            programString = "       LAYER_SPACE = " + QString::number(tempIntervalEnable[2]) +  " :" + QString::number(tempIntervalValue[2]) + "mm;";
            programList.append(programString);

            //BOTTOM
            programString = "   BOTTOM:";
            programList.append(programString);
            for(int j = 0; j < palletStackInfo[i].stackStylePointInfo.size();j++)
            {
                //行点 是否写入
                if(1 == j && 1 == tempRow)
                {
                    continue;//
                }
                //列点 是否写入
                if(2 == j && 1 == tempCol)
                {
                    continue;//
                }
                //层点 是否写入
                if(3 == j && 1 == tempLayer)
                {
                    continue;//
                }
                //辅助点 是否写入 //stackStylePointInfo size() == 5个 但 没有辅助点,则循环break
                if(4 == j && palletStackInfo[i].auxiliary == EM_STACK_AUX_NONE)
                {
                    break;//退出,第五个不写入文件
                }

                //***************************************************************
//                qDebug()<< __FUNCTION__<<"*****"<<__LINE__<<endl;
                row = palletStackInfo[i].stackStylePointInfo[j].rowColumnLayer[0];
                col = palletStackInfo[i].stackStylePointInfo[j].rowColumnLayer[1];
                layer = palletStackInfo[i].stackStylePointInfo[j].rowColumnLayer[2];

//                qDebug()<< __FUNCTION__<<"*****"<<__LINE__<<endl;

                programString = "       P [" + QString::number(row) + "," + QString::number(col) + ","+
                        QString::number(layer) + "]{";
                programList.append(programString);
                programString = "          GP1:";
                programList.append(programString);


                conString = QString::fromStdString(palletStackInfo[i].stackStylePointInfo[j].stackPoint.configString);
                programString = "          UF : " + QString::number(globalDefaultUserNum) +
                    ", UT : " + QString::number(globalDefaultToolNum) + ", CONFIG :" + conString;
                programList.append(programString);


                programString = "";
                int axisNum = palletStackInfo[i].stackStylePointInfo[j].stackPoint.positionValue.size();
                for(int m = 0; m < axisNum;m++)
                {
                    if(palletStackInfo[i].stackStylePointInfo[j].stackPoint.jointFlag == EM_CF_WORLD_TYPE)
                    {
                        if(m == EM_CF_X)
                        {
                            programString = programString + "          X =       " +
                                    QString::number(palletStackInfo[i].stackStylePointInfo[j].stackPoint.positionValue[m]) + " mm,";
                        }
                        else if(m == EM_CF_Y)
                        {
                            programString = programString + "       Y =       " +
                                    QString::number(palletStackInfo[i].stackStylePointInfo[j].stackPoint.positionValue[m]) + " mm,";
                        }
                        else if(m == EM_CF_Z)
                        {
                            programString = programString + "       Z =       " +
                                    QString::number(palletStackInfo[i].stackStylePointInfo[j].stackPoint.positionValue[m]) + " mm,";

                            programList.append(programString);//加一行
                            programString = "";//此处的空等价于换行了
                        }
                        else if(m == EM_CF_W)
                        {
                            programString = programString + "          W =       " +
                                    QString::number(palletStackInfo[i].stackStylePointInfo[j].stackPoint.positionValue[m]) + " deg,";
                        }
                        else if(m == EM_CF_P)
                        {
                            programString = programString + "       P =       " +
                                    QString::number(palletStackInfo[i].stackStylePointInfo[j].stackPoint.positionValue[m]) + " deg,";
                        }
                        else if(m == EM_CF_R)
                        {
                            programString = programString + "       R =       " +
                                    QString::number(palletStackInfo[i].stackStylePointInfo[j].stackPoint.positionValue[m]) + " deg,";
                            programList.append(programString);
                            programString = "";
                        }
                    }
                    else if(palletStackInfo[i].stackStylePointInfo[j].stackPoint.jointFlag == EM_CF_DEG_TYPE)
                    {
                        jointAngle = palletStackInfo[i].stackStylePointInfo[j].stackPoint.positionValue[m];
                        if((m > 0) && (m % 3 == 0))
                        {
                            programList.append(programString);
                            programString =  "          J"+QString::number(m + 1)+"=        "+  QString::number(jointAngle) + " "+tmpUnit[m];
                            if(m == axisNum - 1)
                            {
                                programList.append(programString);
                            }
                        }
                        else
                        {
                             programString = programString + "          J"+QString::number(m + 1)+"=        "+  QString::number(jointAngle) + " "+tmpUnit[m];
                        }
                        if((m == axisNum - 1)&&(m % 3 != 0))
                        {
                            programList.append(programString);
                        }
                    }

                }
                programString = "       };";
                programList.append(programString);

//                qDebug()<< __FUNCTION__<<"*****"<<__LINE__<<endl;
            }
            programString = "   ROUTE:";
            programList.append(programString);

            qDebug()<< __FUNCTION__<<"*****"<<__LINE__<<endl;

            //*************A_N*************
            int apprSize = palletStackInfo[i].stackPointA_n.size();
            for(int k = 0; k < apprSize;k++)
            {
//                qDebug()<< __FUNCTION__<<"*****"<<__LINE__<<endl;

                programString = "       P [A_"+QString::number(apprSize - k) + "]{";
                //programString = "       P [A_"+QString::number(k + 1) + "]{";//2017-.03.28改为顺序编号,这样ui才能一一对应
                programList.append(programString);
                programString = "          GP1:";
                programList.append(programString);


                conString = QString::fromStdString(palletStackInfo[i].stackPointA_n[k].configString);
                programString = "          UF : " + QString::number(globalDefaultUserNum) +
                    ", UT : " + QString::number(globalDefaultToolNum) + ", CONFIG :" + conString;
                programList.append(programString);

                programString = "";
                int axisNum = palletStackInfo[i].stackPointA_n[k].positionValue.size();
                for(int m = 0; m < axisNum;m++)
                {
                    jointAngle = palletStackInfo[i].stackPointA_n[k].positionValue[m];

                    if(palletStackInfo[i].stackPointA_n[k].jointFlag == EM_CF_WORLD_TYPE)
                    {
                        if(m == EM_CF_X)
                        {
                            programString = programString + "          X =       " +
                                    QString::number(jointAngle) + " mm,";
                        }
                        else if(m == EM_CF_Y)
                        {
                            programString = programString + "       Y =       " +
                                    QString::number(jointAngle) + " mm,";
                        }
                        else if(m == EM_CF_Z)
                        {
                            programString = programString + "       Z =       " +
                                    QString::number(jointAngle) + " mm,";

                            programList.append(programString);//加一行
                            programString = "";//此处的空等价于换行了
                        }
                        else if(m == EM_CF_W)
                        {
                            programString = programString + "          W =       " +
                                    QString::number(jointAngle) + " deg,";
                        }
                        else if(m == EM_CF_P)
                        {
                            programString = programString + "       P =       " +
                                    QString::number(jointAngle) + " deg,";
                        }
                        else if(m == EM_CF_R)
                        {
                            programString = programString + "       R =       " +
                                    QString::number(jointAngle) + " deg,";
                            programList.append(programString);
                            programString = "";
                        }
                    }
                    else if(palletStackInfo[i].stackPointA_n[k].jointFlag == EM_CF_DEG_TYPE)
                    {
                        if((m > 0) && (m % 3 == 0))
                        {
                            programList.append(programString);
                            programString =  "          J"+QString::number(m + 1)+"=        "+  QString::number(jointAngle) + " "+tmpUnit[m];
                            if(m == axisNum - 1)
                            {
                                programList.append(programString);
                            }
                        }
                        else
                        {
                             programString = programString + "          J"+QString::number(m + 1)+"=        "+  QString::number(jointAngle) + " "+tmpUnit[m];
                        }
                        if((m == axisNum - 1)&&(m % 3 != 0))
                        {
                            programList.append(programString);
                        }
                    }

                }

                programString = "";
                int extAxisNum = palletStackInfo[i].stackPointA_n[k].extPositionValue.size();
                for(int m = 0; m < extAxisNum;m++)
                {
                    jointAngle = palletStackInfo[i].stackPointA_n[k].extPositionValue[m];
                    if((m > 0) && (m % 3 == 0))
                    {
                        programList.append(programString);
                        programString =  "          E"+QString::number(m + 1)+"=        "+  QString::number(jointAngle) + " deg,";
                        if(m == extAxisNum - 1)
                        {
                            programList.append(programString);
                        }
                    }
                    else
                    {
                         programString = programString + "          E"+QString::number(m + 1)+"=        "+  QString::number(jointAngle) + " deg,";
                    }
                    if((m == extAxisNum - 1)&&(m % 3 != 0))
                    {
                        programList.append(programString);
                    }

                    //表示只有一个数据
                    if((1 == extAxisNum) && 0 == m)
                    {
                        programList.append(programString);
                    }
                }

                programString = "       };";
                programList.append(programString);
            }

            //*************BTM*************
            programString = "       P [BTM]{";
            programList.append(programString);
            programString = "          GP1:";
            programList.append(programString);
            //??? direction = palletStackInfo[i].stackPointBTM.direction;

            conString = QString::fromStdString(palletStackInfo[i].stackPointBTM.configString);
            programString = "          UF : " + QString::number(globalDefaultUserNum) +
                ", UT : " + QString::number(globalDefaultToolNum) + ", CONFIG :" + conString;
            programList.append(programString);
            programString = "";
            int axisNum = palletStackInfo[i].stackPointBTM.positionValue.size();
            for(int m = 0; m < axisNum;m++)
            {
                jointAngle = palletStackInfo[i].stackPointBTM.positionValue[m];

                if(palletStackInfo[i].stackPointBTM.jointFlag == EM_CF_WORLD_TYPE)
                {
                    if(m == EM_CF_X)
                    {
                        programString = programString + "          X =       " +
                                QString::number(jointAngle) + " mm,";
                    }
                    else if(m == EM_CF_Y)
                    {
                        programString = programString + "       Y =       " +
                                QString::number(jointAngle) + " mm,";
                    }
                    else if(m == EM_CF_Z)
                    {
                        programString = programString + "       Z =       " +
                                QString::number(jointAngle) + " mm,";

                        programList.append(programString);//加一行
                        programString = "";//此处的空等价于换行了
                    }
                    else if(m == EM_CF_W)
                    {
                        programString = programString + "          W =       " +
                                QString::number(jointAngle) + " deg,";
                    }
                    else if(m == EM_CF_P)
                    {
                        programString = programString + "       P =       " +
                                QString::number(jointAngle) + " deg,";
                    }
                    else if(m == EM_CF_R)
                    {
                        programString = programString + "       R =       " +
                                QString::number(jointAngle) + " deg,";
                        programList.append(programString);
                        programString = "";
                    }
                }
                else if(palletStackInfo[i].stackPointBTM.jointFlag == EM_CF_DEG_TYPE)
                {
                    if((m > 0) && (m % 3 == 0))
                    {
                        programList.append(programString);
                        programString =  "          J"+QString::number(m + 1)+"=        "+  QString::number(jointAngle) + " "+tmpUnit[m];
                        if(m == axisNum - 1)
                        {
                            programList.append(programString);
                        }
                    }
                    else
                    {
                         programString = programString + "          J"+QString::number(m + 1)+"=        "+  QString::number(jointAngle) + " "+tmpUnit[m];
                    }
                    if((m == axisNum - 1)&&(m % 3 != 0))
                    {
                        programList.append(programString);
                    }
                }
            }
            programString = "";
            int extAxisNum = palletStackInfo[i].stackPointBTM.extPositionValue.size();
            for(int m = 0; m < extAxisNum;m++)
            {
                jointAngle = palletStackInfo[i].stackPointBTM.extPositionValue[m];
                if((m > 0) && (m % 3 == 0))
                {
                    programList.append(programString);
                    programString =  "          E"+QString::number(m + 1)+"=        "+  QString::number(jointAngle) + " deg,";
                    if(m == extAxisNum - 1)
                    {
                        programList.append(programString);
                    }
                }
                else
                {
                     programString = programString + "          E"+QString::number(m + 1)+"=        "+  QString::number(jointAngle) + " deg,";
                }
                if((m == extAxisNum - 1)&&(m % 3 != 0))
                {
                    programList.append(programString);
                }

                //表示只有一个数据
                if((1 == extAxisNum) && 0 == m)
                {
                    programList.append(programString);
                }
            }
            programString = "       };";
            programList.append(programString);

            //*************R_N*************
            int fleeSize = palletStackInfo[i].stackPointR_n.size();
            for(int k = 0; k < fleeSize;k++)
            {
//                qDebug()<< __FUNCTION__<<"*****"<<__LINE__<<endl;

                programString = "       P [R_"+QString::number(fleeSize - k) + "]{";
                //programString = "       P [R_"+QString::number(k + 1) + "]{";//2017-.03.28改为顺序编号,这样ui才能一一对应
                programList.append(programString);
                programString = "          GP1:";
                programList.append(programString);


                conString = QString::fromStdString(palletStackInfo[i].stackPointR_n[k].configString);
                programString = "          UF : " + QString::number(globalDefaultUserNum) +
                    ", UT : " + QString::number(globalDefaultToolNum) + ", CONFIG :" + conString;
                programList.append(programString);

                programString = "";
                int axisNum = palletStackInfo[i].stackPointR_n[k].positionValue.size();
                for(int m = 0; m < axisNum;m++)
                {
                    jointAngle = palletStackInfo[i].stackPointR_n[k].positionValue[m];

                    if(palletStackInfo[i].stackPointR_n[k].jointFlag == EM_CF_WORLD_TYPE)
                    {
                        if(m == EM_CF_X)
                        {
                            programString = programString + "          X =       " +
                                    QString::number(jointAngle) + " mm,";
                        }
                        else if(m == EM_CF_Y)
                        {
                            programString = programString + "       Y =       " +
                                    QString::number(jointAngle) + " mm,";
                        }
                        else if(m == EM_CF_Z)
                        {
                            programString = programString + "       Z =       " +
                                    QString::number(jointAngle) + " mm,";

                            programList.append(programString);//加一行
                            programString = "";//此处的空等价于换行了
                        }
                        else if(m == EM_CF_W)
                        {
                            programString = programString + "          W =       " +
                                    QString::number(jointAngle) + " deg,";
                        }
                        else if(m == EM_CF_P)
                        {
                            programString = programString + "       P =       " +
                                    QString::number(jointAngle) + " deg,";
                        }
                        else if(m == EM_CF_R)
                        {
                            programString = programString + "       R =       " +
                                    QString::number(jointAngle) + " deg,";
                            programList.append(programString);
                            programString = "";
                        }
                    }
                    else if(palletStackInfo[i].stackPointR_n[k].jointFlag == EM_CF_DEG_TYPE)
                    {
                        if((m > 0) && (m % 3 == 0))
                        {
                            programList.append(programString);
                            programString =  "          J"+QString::number(m + 1)+"=        "+  QString::number(jointAngle) + " "+tmpUnit[m];
                            if(m == axisNum - 1)
                            {
                                programList.append(programString);
                            }
                        }
                        else
                        {
                             programString = programString + "          J"+QString::number(m + 1)+"=        "+  QString::number(jointAngle) + " "+tmpUnit[m];
                        }
                        if((m == axisNum - 1)&&(m % 3 != 0))
                        {
                            programList.append(programString);
                        }
                    }
                }

                programString = "";
                int extAxisNum = palletStackInfo[i].stackPointR_n[k].extPositionValue.size();
                for(int m = 0; m < extAxisNum;m++)
                {
                    jointAngle = palletStackInfo[i].stackPointR_n[k].extPositionValue[m];
                    if((m > 0) && (m % 3 == 0))
                    {
                        programList.append(programString);
                        programString =  "          E"+QString::number(m + 1)+"=        "+  QString::number(jointAngle) + " deg,";
                        if(m == extAxisNum - 1)
                        {
                            programList.append(programString);
                        }
                    }
                    else
                    {
                         programString = programString + "          E"+QString::number(m + 1)+"=        "+  QString::number(jointAngle) + " deg,";
                    }
                    if((m == extAxisNum - 1)&&(m % 3 != 0))
                    {
                        programList.append(programString);
                    }

                    //表示只有一个数据
                    if((1 == extAxisNum) && 0 == m)
                    {
                        programList.append(programString);
                    }
                }

                programString = "       };";
                programList.append(programString);
            }

        }
        programString = "/APPL";
        programList.append(programString);

        qDebug()<< __FUNCTION__<<"*****"<<__LINE__<<endl;
    }
//#endif

    programString = "/MN";
    programList.append(programString);

    for(int i = 0;i < cmdStrWriteList.size();i++)
    {
        programString = QString::number(i+1) + ":" + cmdStrWriteList[i];
        programList.append(programString);
//        qDebug()<<__FUNCTION__<<"****"<<__LINE__<<"***"<<cmdStringList[i];
    }
    programString = "/POS";
    programList.append(programString);


    for(int i = 0; i < getPointProList.size();i++)
    {
        //此处为按顺序,如果点编号错误,那么保存一次后也会纠正正常?
        programString = "P[" + QString::number(i+1) + "]{";//programString = "P[" + QString::number(getPointProList[i].pointNum) + "]{";
//            qDebug() <<__LINE__ <<"***programString***"<<programString<<endl;
        programList.append(programString);
        programString = "   GP"+QString::number(1) + ":";
//            qDebug() <<__LINE__ <<"***programString***"<<programString<<endl;
        programList.append(programString);

        if(getPointProList[i].jointFlag == EM_CF_WORLD_TYPE)
        {
            programString = "       UF :" + QString::number(getPointProList[i].ufValue) +
                    ", UT :" + QString::number(getPointProList[i].utValue) + "," + "       CONFIG:"+
                    QString::fromStdString(getPointProList[i].configString);
        }
        else if(getPointProList[i].jointFlag == EM_CF_DEG_TYPE)
        {
            programString = "       UF :" + QString::number(getPointProList[i].ufValue) +
                    ", UT :" + QString::number(getPointProList[i].utValue) + "," + "       "+
                    QString::fromStdString(getPointProList[i].configString);
        }
//            qDebug() <<__LINE__ <<"***programString***"<<programString<<endl;
        programList.append(programString);

//            qDebug()<<__FUNCTION__<<"==="<<__LINE__<<
//                      "==USEER==="<<getPointProList[i].ufValue<<
//                      "==TOOL===="<<getPointProList[i].utValue<<endl;

        programString = "";
        for(int j = 0; j < getPointProList[i].positionValue.size();j++)
        {
//                qDebug() <<"****j**"<<j<<"***jointFlag***"<<getPointProList[i].jointFlag<<endl;
            if(getPointProList[i].jointFlag == EM_CF_WORLD_TYPE)
            {
                if(j == EM_CF_X)
                {
                    programString = programString + "       X =       " +
                            QString::number(getPointProList[i].positionValue[j]) + " mm,";
                }
                else if(j == EM_CF_Y)
                {
                    programString = programString + "       Y =       " +
                            QString::number(getPointProList[i].positionValue[j]) + " mm,";
                }
                else if(j == EM_CF_Z)
                {
                    programString = programString + "       Z =       " +
                            QString::number(getPointProList[i].positionValue[j]) + " mm,";

                    programList.append(programString);//加一行
                    programString = "";//此处的空等价于换行了
                }
                else if(j == EM_CF_W)
                {
                    programString = programString + "       W =       " +
                            QString::number(getPointProList[i].positionValue[j]) + " deg,";
                }
                else if(j == EM_CF_P)
                {
                    programString = programString + "       P =       " +
                            QString::number(getPointProList[i].positionValue[j]) + " deg,";
                }
                else if(j == EM_CF_R)
                {
                    programString = programString + "       R =       " +
                            QString::number(getPointProList[i].positionValue[j]) + " deg,";
                    programList.append(programString);
                    programString = "";
                }
            }
            else if(getPointProList[i].jointFlag == EM_CF_DEG_TYPE)
            {
                if((j % 3 == 0) && (j > 0))
                {
//                        qDebug() <<__LINE__ <<"***programString***"<<programString<<endl;
                    programList.append(programString);
                    programString = "       J" + QString::number(j + 1) + "=       " +
                            QString::number(getPointProList[i].positionValue[j])+tmpUnit[j];
//                    qDebug()<<__LINE__<<"*****"<<i<<" "<<j<<"**programString***"<<programString<<endl;

                    if(j == getPointProList[i].positionValue.size() - 1)
                    {
//                            qDebug() <<__LINE__ <<"***programString***"<<programString<<endl;
                        programList.append(programString);
                    }
                }
                else
                {
                    programString = programString + "       " + "J" + QString::number(j + 1) + "=       " +
                            QString::number(getPointProList[i].positionValue[j])+tmpUnit[j];
                }
                if((j == getPointProList[i].positionValue.size() - 1)&&
                        (j % 3 != 0))
                {
//                        qDebug() <<__LINE__ <<"***programString***"<<programString<<endl;
                    programList.append(programString);
                }
            }
        }

        //外部轴数据插入
        programString = "";

        for(int j = 0; j < getPointProList[i].extPositionValue.size();j++)
        {
            if((j % 3 == 0) && (j > 0))
            {
//                    qDebug() <<__LINE__ <<"***programString***"<<programString<<endl;
                programList.append(programString);
                programString = "       E" + QString::number(j + 1) + "=       " +
                        QString::number(getPointProList[i].extPositionValue[j])+"deg,";
//                    qDebug()<<__LINE__<<"*****"<<getPointProList[i].extPositionValue[j]<<"**programString***"<<programString<<endl;
                if(j == getPointProList[i].extPositionValue.size() - 1)
                {
//                        qDebug() <<__LINE__ <<"***programString***"<<programString<<endl;
                    programList.append(programString);
                }
            }
            else
            {
                programString = programString + "       " + "E" + QString::number(j + 1) + "=       " +
                        QString::number(getPointProList[i].extPositionValue[j])+"deg,";
            }

            if((j == getPointProList[i].extPositionValue.size() - 1)&&(j % 3 != 0))
            {
//                    qDebug() <<__LINE__ <<"***programString***"<<programString<<endl;
                programList.append(programString);
            }

            //表示只有一个数据
            if((1 == getPointProList[i].extPositionValue.size()) && 0 == j)
            {
                programList.append(programString);
            }
        }

        programString = "};";
        programList.append(programString);
    }

    programString = "/END";
    programList.append(programString);


    QFile file(currentRobotFileAddress+"program/" + strFilePath);
    file.resize(0);
    if(file.open(QIODevice::ReadWrite | QIODevice::Text))
    {
        QTextStream in(&file);

        for(int i = 0;i < programList.size();i++)
        {
            if(programList[i].contains("\n"))
            {
                programList[i].replace("\n","");
            }
//            qDebug() << "*****"<<__FUNCTION__<<"****"<<__LINE__<<"**programList***"<<programList[i]<<endl;
            in << programList[i]<<"\n";
        }

        file.close();
    }

    //point test
//    qDebug()<<"end "<<getPointProList.size();
//    for(int i = 0;i<getPointProList.size();i++)
//    {
//        qDebug()<<i<<":"<<getPointProList[i].pointNum;
//    }
}

QString FileData::readProgramToMD5(QString strFilePath)
{
    strFilePath = currentRobotFileAddress+"program/" + strFilePath;//文件地址

    return getMD5(strFilePath);
}

QString FileData::readFileToMD5(QString strFilePath)
{
    return getMD5(strFilePath);
}

QString FileData::getMD5(QString wholePath)
{
    QString md5;

    QFile file(wholePath);

    if(file.open(QIODevice::ReadOnly))
    {
        QByteArray bArray = QCryptographicHash::hash(file.readAll(),QCryptographicHash::Md5);

        //md5 = QString(bArray.toHex()).toUpper();//大写
        md5 = QString(bArray.toHex());

        file.close();
    }
    else
    {
        md5 = -1;
    }

    return md5;
}

bool FileData::checkMD5(QString checkMD5, QString wholePath)
{
    if(checkMD5 == getMD5(wholePath))
    {
        return true;
    }
    else
    {
        return false;
    }
}

QStringList FileData::translateCmdList(int language , QStringList cmd)
{
    //language 用于区分语言:目前不需要,只有中文

    QStringList returnCmdList = cmd;//返回用
    for(int i = 0; i < cmd.size(); i++)
    {
        //此处可能有问题\\/\\/
        QRegExp rx("\\s*[\\/\\/]{0,2}\\s*([A-Z_]*)\\-?\\s*([BEXND]{0,3})\\s*\\_?\\d*\\s*([PAL]{0,3})\\s*(.*)");
        cmd[i].indexOf(rx);

        QRegExp rxForward("\\s*([A-Z_]*)\\s+(.*)");
        if(i > 0)
        {
            QString instruction = cmd[i - 1];
            instruction.indexOf(rxForward);
        }


        if((("J" == rx.cap(1)) || ("L" == rx.cap(1)) || ("C" == rx.cap(1)) || ("A" == rx.cap(1)) || ("C" == rxForward.cap(1)))
                && ("PAL" != rx.cap(3)))
        {
//            returnCmdList[i].replace(QRegExp("^\\s*J"), "关节");
//            returnCmdList[i].replace(QRegExp("^\\s*L"), "直线");
//            returnCmdList[i].replace(QRegExp("^\\s*C"), "圆弧");
            returnCmdList[i].replace("J ", "关节 ");
            returnCmdList[i].replace("L ", "直线 ");
            returnCmdList[i].replace("C ", "圆弧 ");
            returnCmdList[i].replace(QRegExp("[P]\\s*[[]"), "位置[");
            returnCmdList[i].replace(QRegExp("PR"), "位置暂存器");
            returnCmdList[i].replace(QRegExp("[R][[]"), "寄存器[");

            returnCmdList[i].replace("FINE", "通过");
            returnCmdList[i].replace("CNT", "接近");

            returnCmdList[i].replace("DI", "数字输入信号");
            returnCmdList[i].replace("ON", "开");
            returnCmdList[i].replace("OFF", "关");

            returnCmdList[i].replace("Skip", "跳过");
            returnCmdList[i].replace("LBL", "标签");

            returnCmdList[i].replace("Wjnt", "手腕关节动作");
            returnCmdList[i].replace("INC", "增量运动");
            returnCmdList[i].replace("ACC", "加减速倍率");
            returnCmdList[i].replace("EV", "附加轴速度");
            returnCmdList[i].replace("PTH", "路径");
            returnCmdList[i].replace(QRegExp("[^_]Offset"), " 位置补偿");
            returnCmdList[i].replace("Tool_Offset", "工具补偿");
        }
        else if("PALLETIZING" == rx.cap(1))
        {
            returnCmdList[i].replace("PALLETIZING", "码垛");
            returnCmdList[i].replace("END", "尾");
        }
        else if((("J" == rx.cap(1)) || ("L" == rx.cap(1))) && ("PAL" == rx.cap(3)))
        {
            returnCmdList[i].replace("J ", "关节 ");
            returnCmdList[i].replace("L ", "直线 ");
            returnCmdList[i].replace("PAL", "码垛");
            returnCmdList[i].replace("A_", "接近点_");
            returnCmdList[i].replace("R_", "逃离点_");
            returnCmdList[i].replace("BTM", "堆栈点");
            returnCmdList[i].replace("FINE", "通过");
            returnCmdList[i].replace("CNT", "接近");
            returnCmdList[i].replace("DI", "数字输入信号");
            returnCmdList[i].replace("ON", "开");
            returnCmdList[i].replace("OFF", "关");
            returnCmdList[i].replace("Skip,LBL", "跳过,标签");
        }
        else if("IF" == rx.cap(1))
        {
            returnCmdList[i].replace("IF", "如果条件");
            returnCmdList[i].replace("JMP LBL", "跳转到 标签");
            returnCmdList[i].replace("CALL", "调用程序");

            returnCmdList[i].replace("R[", "寄存器[");
            returnCmdList[i].replace("PL[", "栈板寄存器");
            returnCmdList[i].replace("PR[", "位置寄存器");

            returnCmdList[i].replace("AO", "模拟输出信号");
            returnCmdList[i].replace("AI", "模拟输入信号");
            returnCmdList[i].replace("GO", "群组输出信号");
            returnCmdList[i].replace("GI", "群组输入信号");
            returnCmdList[i].replace("DO", "数字输出信号");
            returnCmdList[i].replace("DI", "数字输入信号");
            returnCmdList[i].replace("RO", "机器人输出信号");
            returnCmdList[i].replace("RI", "机器人输入信号");
            returnCmdList[i].replace("SO", "操作面板输出信号");
            returnCmdList[i].replace("SI", "操作面板输入信号");
            returnCmdList[i].replace("UO", "外围设备输出信号");
            returnCmdList[i].replace("UI", "外围设备输入信号");

            returnCmdList[i].replace("ON", "开");
            returnCmdList[i].replace("OFF", "关");

            returnCmdList[i].replace("AND", "且");
            returnCmdList[i].replace("OR", "或");
        }
        else if(("LBL" == rx.cap(1)) || ("JMP" == rx.cap(1)) || ("END" == rx.cap(1)) || ("PAUSE" == rx.cap(1))
                || ("ABORT" == rx.cap(1)) || ("CALL" == rx.cap(1)) || ("RUN" == rx.cap(1)))
        {
            returnCmdList[i].replace("LBL", "标签");
            returnCmdList[i].replace("JMP", "跳转到");
            returnCmdList[i].replace("END", "结束");
            returnCmdList[i].replace("PAUSE", "暂停");
            returnCmdList[i].replace("ABORT", "终止");
            returnCmdList[i].replace("CALL", "调用程序");
            returnCmdList[i].replace("RUN", "开任务");

            returnCmdList[i].replace("R[", "寄存器[");
        }
        else if("WAIT" == rx.cap(1))
        {
            returnCmdList[i].replace("WAIT", "等待");

            returnCmdList[i].replace("R[", "寄存器[");
            returnCmdList[i].replace("AO", "模拟输出信号");
            returnCmdList[i].replace("AI", "模拟输入信号");
            returnCmdList[i].replace("GO", "群组输出信号");
            returnCmdList[i].replace("GI", "群组输入信号");
            returnCmdList[i].replace("DO", "数字输出信号");
            returnCmdList[i].replace("DI", "数字输入信号");
            returnCmdList[i].replace("RO", "机器人输出信号");
            returnCmdList[i].replace("RI", "机器人输入信号");
            returnCmdList[i].replace("SO", "操作面板输出信号");
            returnCmdList[i].replace("SI", "操作面板输入信号");
            returnCmdList[i].replace("UO", "外围设备输出信号");
            returnCmdList[i].replace("UI", "外围设备输入信号");

            returnCmdList[i].replace(QRegExp("ON[^+]"), "开");
            returnCmdList[i].replace(QRegExp("OFF[^-]"), "关");
            returnCmdList[i].replace("ON+", "信号上升沿");
            returnCmdList[i].replace("OFF-", "信号下降沿");

            returnCmdList[i].replace("AND", "且");
            returnCmdList[i].replace("OR", "或");

            returnCmdList[i].replace("TIMEOUT", "等待超时转移");
            returnCmdList[i].replace("LBL", "标签");
        }
        else if(("FOR" == rx.cap(1)) || ("ENDFOR" == rx.cap(1)))
        {
            returnCmdList[i].replace("FOR ", "循环开始 ");
            returnCmdList[i].replace("END循环开始", "循环结束");
            returnCmdList[i].replace("ENDFOR", "循环结束");

            returnCmdList[i].replace("R[", "寄存器[");
            returnCmdList[i].replace("A寄存器", "自变量寄存器");

            returnCmdList[i].replace(" TO", " 增加到");
            returnCmdList[i].replace("DOWNTO", "减小到");
        }
        else if(("R" == rx.cap(1))|| ("GR" == rx.cap(1)) || ("PR" == rx.cap(1)) || ("PL" == rx.cap(1)))
        {
            returnCmdList[i].replace("R[", "寄存器[");
            returnCmdList[i].replace("G寄存器", "群组寄存器");
            returnCmdList[i].replace("PR[", "位置寄存器[");
            returnCmdList[i].replace("PL[", "栈板寄存器[");

            returnCmdList[i].replace("A寄存器", "自变量寄存器");
            returnCmdList[i].replace("AO", "模拟输出信号");
            returnCmdList[i].replace("AI", "模拟输入信号");
            returnCmdList[i].replace("GO", "群组输出信号");
            returnCmdList[i].replace("GI", "群组输入信号");
            returnCmdList[i].replace("DO", "数字输出信号");
            returnCmdList[i].replace("DI[", "数字输入信号[");
            returnCmdList[i].replace("RO", "机器人输出信号");
            returnCmdList[i].replace("RI", "机器人输入信号");
            returnCmdList[i].replace("SO", "操作面板输出信号");
            returnCmdList[i].replace("SI", "操作面板输入信号");
            returnCmdList[i].replace("UO", "外围设备输出信号");
            returnCmdList[i].replace("UI", "外围设备输入信号");

//            returnCmdList[i].replace("TIMER[", "计时器[");
            returnCmdList[i].replace("TIME寄存器", "计时器");
            returnCmdList[i].replace("TIMER_OVERFLOW", "计时器溢出旗标");
            returnCmdList[i].replace("JPOS", "当前位置关节坐标");
            returnCmdList[i].replace("LPOS", "当前位置直角坐标");
            returnCmdList[i].replace("UFRAME", "用户坐标系");
            returnCmdList[i].replace("UTOOL", "工具坐标系");

            returnCmdList[i].replace("MOD", "求余");
            returnCmdList[i].replace("DIV", "整除");
        }
        else if(("SELECT" == rx.cap(1)) || ("ELSE" == rx.cap(1)))
        {
            returnCmdList[i].replace("SELECT", "条件选择");
            returnCmdList[i].replace("ELSE", "其它值");
            returnCmdList[i].replace("R[", "寄存器[");
            returnCmdList[i].replace("JMP LBL", "跳转到 标签");
            returnCmdList[i].replace("CALL", "调用程序");
        }
        else if("SKIP" == rx.cap(1))
        {
            returnCmdList[i].replace("SKIP", "跳过条件");
            returnCmdList[i].replace("Skip", "跳过");
            returnCmdList[i].replace("LBL", "标签");

            returnCmdList[i].replace("R[", "寄存器[");
            returnCmdList[i].replace("PULSE", "脉冲");

            returnCmdList[i].replace("AO", "模拟输出信号");
            returnCmdList[i].replace("AI", "模拟输入信号");
            returnCmdList[i].replace("GO", "群组输出信号");
            returnCmdList[i].replace("GI", "群组输入信号");
            returnCmdList[i].replace("DO", "数字输出信号");
            returnCmdList[i].replace("DI", "数字输入信号");
            returnCmdList[i].replace("RO", "机器人输出信号");
            returnCmdList[i].replace("RI", "机器人输入信号");
            returnCmdList[i].replace("SO", "操作面板输出信号");
            returnCmdList[i].replace("SI", "操作面板输入信号");
            returnCmdList[i].replace("UO", "外围设备输出信号");
            returnCmdList[i].replace("UI", "外围设备输入信号");

            returnCmdList[i].replace(QRegExp("ON[^+]"), "开");
            returnCmdList[i].replace(QRegExp("OFF[^-]"), "关");
            returnCmdList[i].replace("ON+", "信号上升沿");
            returnCmdList[i].replace("OFF-", "信号下降沿");

            returnCmdList[i].replace("AND", "且");
            returnCmdList[i].replace("OR", "或");
        }
        else if("DO" == rx.cap(1) || "AO" == rx.cap(1))
        {
            returnCmdList[i].replace("R[", "寄存器[");
            returnCmdList[i].replace("PULSE", "脉冲");

            returnCmdList[i].replace("AO", "模拟输出信号");
            returnCmdList[i].replace("AI", "模拟输入信号");
            returnCmdList[i].replace("GO", "群组输出信号");
            returnCmdList[i].replace("GI", "群组输入信号");
            returnCmdList[i].replace("DO", "数字输出信号");
            returnCmdList[i].replace("DI", "数字输入信号");
            returnCmdList[i].replace("RO", "机器人输出信号");
            returnCmdList[i].replace("RI", "机器人输入信号");
            returnCmdList[i].replace("SO", "操作面板输出信号");
            returnCmdList[i].replace("SI", "操作面板输入信号");
            returnCmdList[i].replace("UO", "外围设备输出信号");
            returnCmdList[i].replace("UI", "外围设备输入信号");

            returnCmdList[i].replace("ON", "开");
            returnCmdList[i].replace("OFF", "关");
        }
        else if(("DJ" == rx.cap(1)) || ("DWJ" == rx.cap(1)) || ("DTJ" == rx.cap(1)) || ("DDJ" == rx.cap(1)) ||
                ("FJ" == rx.cap(1)) || ("FWJ" == rx.cap(1)) || ("FTJ" == rx.cap(1)) || ("FDJ" == rx.cap(1)))
        {
            returnCmdList[i].replace("DDJ ", "取料完成 ");
            returnCmdList[i].replace("FDJ ", "放料完成 ");

            returnCmdList[i].replace("DJ ", "取料 ");
            returnCmdList[i].replace("DWJ ", "取料等待 ");
            returnCmdList[i].replace("DTJ ", "取料上方 ");

            returnCmdList[i].replace("FJ ", "放料 ");
            returnCmdList[i].replace("FWJ ", "放料等待 ");
            returnCmdList[i].replace("FTJ ", "放料上方 ");


            returnCmdList[i].replace(QRegExp("[P]\\s*[[]"), "位置[");
            returnCmdList[i].replace(QRegExp("PR"), "位置暂存器");
            returnCmdList[i].replace(QRegExp("[R][[]"), "寄存器[");

            returnCmdList[i].replace("FINE", "通过");
            returnCmdList[i].replace("CNT", "接近");

            returnCmdList[i].replace("DI", "数字输入信号");
            returnCmdList[i].replace("ON", "开");
            returnCmdList[i].replace("OFF", "关");

            returnCmdList[i].replace("Skip", "跳过");
            returnCmdList[i].replace("LBL", "标签");

            returnCmdList[i].replace("Wjnt", "手腕关节动作");
            returnCmdList[i].replace("INC", "增量运动");
            returnCmdList[i].replace("ACC", "加减速倍率");
            returnCmdList[i].replace("EV", "附加轴速度");
            returnCmdList[i].replace("PTH", "路径");
            returnCmdList[i].replace(QRegExp("[^_]Offset"), " 位置补偿");
            returnCmdList[i].replace("Tool_Offset", "工具补偿");
        }
        else if(("UTOOL" == rx.cap(1)) || ("UFRAME" == rx.cap(1)) || ("UTOOL_NUM" == rx.cap(1)) || ("UFRAME_NUM" == rx.cap(1)))
        {
            returnCmdList[i].replace("UTOOL[", "工具坐标系[");
            returnCmdList[i].replace("UFRAME[", "用户坐标系[");
            returnCmdList[i].replace("UTOOL_NUM", "工具坐标系号码");
            returnCmdList[i].replace("UFRAME_NUM", "用户坐标系号码");
            returnCmdList[i].replace("R[", "寄存器[");
            returnCmdList[i].replace("P寄存器", "位置寄存器");
        }
        else if(("RSR" == rx.cap(1)) || ("UALM" == rx.cap(1)) || ("TIMER" == rx.cap(1)) || ("OVERRIDE" == rx.cap(1))
                || ("MESSAGE" == rx.cap(1)) || ("JOINT_MAX_SPEED" == rx.cap(1)) || ("LINEAR_MAX_SPEED" == rx.cap(1)))
        {
            returnCmdList[i].replace("RSR", "启动请求信号");
            returnCmdList[i].replace("UALM", "用户报警");
            returnCmdList[i].replace("TIMER", "计时器");
            returnCmdList[i].replace("OVERRIDE", "速度倍率");
            returnCmdList[i].replace("MESSAGE", "消息");
            returnCmdList[i].replace("JOINT_MAX_SPEED", "关节最大速度");
            returnCmdList[i].replace("LINEAR_MAX_SPEED", "直线最大速度");

            returnCmdList[i].replace("ENABLE", "有效");
            returnCmdList[i].replace("DISABLE", "无效");

            returnCmdList[i].replace("START", "启动");
            returnCmdList[i].replace("STOP", "停止");
            returnCmdList[i].replace("RESET", "复位");

            returnCmdList[i].replace("R[", "寄存器[");
        }
        //其他
        else
        {
            returnCmdList[i].replace("Tool_Offset", "工具补偿");
            returnCmdList[i].replace("Offset", "位置补偿");
            returnCmdList[i].replace("PR[", "位置寄存器[");
            returnCmdList[i].replace("R[", "寄存器[");
        }
    }

    return returnCmdList;
}

